github.com/StackExchange/DNSControl@v0.2.8/models/quotes_test.go (about) 1 package models 2 3 import ( 4 "testing" 5 ) 6 7 func TestIsQuoted(t *testing.T) { 8 tests := []struct { 9 d1 string 10 e1 bool 11 }{ 12 {``, false}, 13 {`foo`, false}, 14 {`""`, true}, 15 {`"a"`, true}, 16 {`"bb"`, true}, 17 {`"ccc"`, true}, 18 {`"aaa" "bbb"`, true}, 19 } 20 for i, test := range tests { 21 r := IsQuoted(test.d1) 22 if r != test.e1 { 23 t.Errorf("%v: expected (%v) got (%v)", i, test.e1, r) 24 } 25 } 26 } 27 28 func TestStripQuotes(t *testing.T) { 29 tests := []struct { 30 d1 string 31 e1 string 32 }{ 33 {``, ``}, 34 {`a`, `a`}, 35 {`bb`, `bb`}, 36 {`ccc`, `ccc`}, 37 {`dddd`, `dddd`}, 38 {`"A"`, `A`}, 39 {`"BB"`, `BB`}, 40 {`"CCC"`, `CCC`}, 41 {`"DDDD"`, `DDDD`}, 42 {`"EEEEE"`, `EEEEE`}, 43 {`"aaa" "bbb"`, `aaa" "bbb`}, 44 } 45 for i, test := range tests { 46 r := StripQuotes(test.d1) 47 if r != test.e1 { 48 t.Errorf("%v: expected (%v) got (%v)", i, test.e1, r) 49 } 50 } 51 } 52 53 func TestSetTxtParse(t *testing.T) { 54 tests := []struct { 55 d1 string 56 e1 string 57 e2 []string 58 }{ 59 {`foo`, `foo`, []string{`foo`}}, 60 {`"foo"`, `foo`, []string{`foo`}}, 61 {`"foo bar"`, `foo bar`, []string{`foo bar`}}, 62 {`foo bar`, `foo bar`, []string{`foo bar`}}, 63 {`"aaa" "bbb"`, `aaa`, []string{`aaa`, `bbb`}}, 64 } 65 for i, test := range tests { 66 ls := ParseQuotedTxt(test.d1) 67 if ls[0] != test.e1 { 68 t.Errorf("%v: expected Target=(%v) got (%v)", i, test.e1, ls[0]) 69 } 70 if len(ls) != len(test.e2) { 71 t.Errorf("%v: expected TxtStrings=(%v) got (%v)", i, test.e2, ls) 72 } 73 for i := range ls { 74 if len(ls[i]) != len(test.e2[i]) { 75 t.Errorf("%v: expected TxtStrings=(%v) got (%v)", i, test.e2, ls) 76 } 77 } 78 } 79 }