github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/escape/escape_test.go (about) 1 package escape 2 3 import ( 4 "testing" 5 6 "github.com/lmorg/murex/test/count" 7 ) 8 9 // TestCommandLine checks the escape.CommandLine function escapes all values as expected 10 func TestCommandLine(t *testing.T) { 11 s := []string{ 12 "abcdefghijklmnopqrstuvwxyz", 13 "ABCDEFGHIJKLMNOPQWERTVWXYZ", 14 "1234567890", 15 `!"£$%^&*()_+[]{};'#:@~\|,./<>?`, 16 "`", 17 " \t\r\n", 18 } 19 20 for i := range s { 21 count.Tests(t, len(s[i])) // we are testing every character in batches of strings 22 } 23 24 CommandLine(s) 25 26 if s[0] != "abcdefghijklmnopqrstuvwxyz" { 27 t.Errorf("Lower case alphabet has been modified to: %s", s[0]) 28 } 29 30 if s[1] != "ABCDEFGHIJKLMNOPQWERTVWXYZ" { 31 t.Errorf("Upper case alphabet has been modified to: %s", s[1]) 32 } 33 34 if s[2] != "1234567890" { 35 t.Errorf("Numeric characters have been modified to: %s", s[2]) 36 } 37 38 if s[3] != `!\"£\$%^&\*\(\)_+[]{};\'\#:\@~\\\|,./\<\>\?` { 39 t.Errorf("Extended characters have not been modified correctly: %s", s[3]) 40 } 41 42 if s[4] != "`" { 43 t.Errorf("Extended characters have not been modified correctly: %s", s[4]) 44 } 45 46 if s[5] != `\ \t\r\n` { 47 t.Errorf("White space has not been modified correctly") 48 } 49 } 50 51 // TestTable checks the escape.Table function escapes all values as expected 52 func TestTable(t *testing.T) { 53 s := []string{ 54 "abcdefghijklmnopqrstuvwxyz", 55 "ABCDEFGHIJKLMNOPQWERTVWXYZ", 56 "1234567890", 57 "!\"£$%^&*()_+[]{};'#:@~\\|,./<>?", 58 "`", 59 " \t\r\n", 60 } 61 62 for i := range s { 63 count.Tests(t, len(s[i])) // we are testing every character in batches of strings 64 } 65 66 Table(s) 67 68 if s[0] != "abcdefghijklmnopqrstuvwxyz" { 69 t.Errorf("Lower case alphabet has been modified to: %s", s[0]) 70 } 71 72 if s[1] != "ABCDEFGHIJKLMNOPQWERTVWXYZ" { 73 t.Errorf("Upper case alphabet has been modified to: %s", s[1]) 74 } 75 76 if s[2] != "1234567890" { 77 t.Errorf("Numeric characters have been modified to: %s", s[2]) 78 } 79 80 if s[3] != `!\"£\$%^&*()_+[]{};'#:\@~\\|,./\<\>?` { 81 t.Errorf("Extended characters have not been modified correctly: %s", s[3]) 82 } 83 84 if s[4] != "`" { 85 t.Errorf("Extended characters have not been modified correctly: %s", s[4]) 86 } 87 88 if s[5] != ` \t\r\n` { 89 t.Errorf("White space has not been modified correctly") 90 } 91 }