Skip to content

Commit

Permalink
chore: rewrite rot13 title and description
Browse files Browse the repository at this point in the history
Fixes #46
  • Loading branch information
ccoVeille committed Jun 3, 2024
1 parent a7d35c1 commit 3908b99
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 75 deletions.
12 changes: 6 additions & 6 deletions cmd/processor_rot13-encode.go → cmd/processor_rot13.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion processors/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var List = []list.Item{
Reverse{},
ReverseLines{},
ReverseLines{},
ROT13Encode{},
ROT13{},
SHA1{},
SHA224{},
SHA256{},
Expand Down
59 changes: 0 additions & 59 deletions processors/rot.go

This file was deleted.

60 changes: 60 additions & 0 deletions processors/rot13.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package processors

import (
"fmt"
"strings"
)

// ROT13 converts string with ROT13 cypher.
// https://en.wikipedia.org/wiki/ROT13
type ROT13 struct{}

func (p ROT13) Name() string {
return "rot13"
}

func (p ROT13) Alias() []string {
return []string{"rot13-encode", "rot13-decode", "rot13-enc", "rot13-dec"}
}

func (p ROT13) Transform(data []byte, _ ...Flag) (string, error) {
return strings.Map(rot13, string(data)), nil
}

func (p ROT13) Flags() []Flag {
return nil
}

func (p ROT13) Title() string {
title := "ROT13 Letter Substitution"
return fmt.Sprintf("%s (%s)", title, p.Name())
}

func (p ROT13) Description() string {
return "Cipher/Decipher your text with ROT13 letter substitution"
}

func (p ROT13) FilterValue() string {
return p.Title()
}

// rot13 private helper function for converting rune into rot13.
func rot13(r rune) rune {
if r >= 'a' && r <= 'z' {
// Rotate lowercase letters 13 places.
if r >= 'm' {
return r - 13
}

return r + 13
} else if r >= 'A' && r <= 'Z' {
// Rotate uppercase letters 13 places.
if r >= 'M' {
return r - 13
}

return r + 13
}
// Do nothing.
return r
}
18 changes: 9 additions & 9 deletions processors/rot_test.go → processors/rot13_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

func TestROT13Encode_Transform(t *testing.T) {
func TestROT13_Transform(t *testing.T) {
type args struct {
data []byte
in1 []Flag
Expand Down Expand Up @@ -36,7 +36,7 @@ func TestROT13Encode_Transform(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := ROT13Encode{}
p := ROT13{}
got, err := p.Transform(tt.args.data, tt.args.in1...)
if (err != nil) != tt.wantErr {
t.Errorf("Transform() error = %v, wantErr %v", err, tt.wantErr)
Expand All @@ -49,7 +49,7 @@ func TestROT13Encode_Transform(t *testing.T) {
}
}

func TestROT13Encode_Command(t *testing.T) {
func TestROT13_Command(t *testing.T) {
test := struct {
alias []string
description string
Expand All @@ -58,14 +58,14 @@ func TestROT13Encode_Command(t *testing.T) {
name string
title string
}{
alias: []string{"rot13", "rot13-enc"},
description: "Encode your text to ROT13",
filterValue: "ROT13 Encode (rot13-encode)",
alias: []string{"rot13-encode", "rot13-decode", "rot13-enc", "rot13-dec"},
description: "Cipher/Decipher your text with ROT13 letter substitution",
filterValue: "ROT13 Letter Substitution (rot13)",
flags: nil,
name: "rot13-encode",
title: "ROT13 Encode (rot13-encode)",
name: "rot13",
title: "ROT13 Letter Substitution (rot13)",
}
p := ROT13Encode{}
p := ROT13{}
if got := p.Alias(); !reflect.DeepEqual(got, test.alias) {
t.Errorf("Alias() = %v, want %v", got, test.alias)
}
Expand Down

0 comments on commit 3908b99

Please sign in to comment.