github.com/xyproto/orbiton/v2@v2.65.12-0.20240516144430-e10a419274ec/strings_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 ) 6 7 func TestCapitalizeWords(t *testing.T) { 8 if capitalizeWords("bob john") != "Bob John" { 9 t.Fail() 10 } 11 } 12 13 func TestWithinBackticks(t *testing.T) { 14 tests := []struct { 15 line string 16 what string 17 expected bool 18 }{ 19 { 20 line: "This is a test `hello` string", 21 what: "hello", 22 expected: true, 23 }, 24 { 25 line: "This is a test `hello world` string", 26 what: "world", 27 expected: true, 28 }, 29 { 30 line: "This is a test `hello` string", 31 what: "world", 32 expected: false, 33 }, 34 { 35 line: "This is a test `hello world` string", 36 what: "hello world", 37 expected: true, 38 }, 39 { 40 line: "This is a test `hello world` string", 41 what: "test", 42 expected: false, 43 }, 44 { 45 line: "`hello` world", 46 what: "hello", 47 expected: true, 48 }, 49 { 50 line: "`hello` world", 51 what: "world", 52 expected: false, 53 }, 54 { 55 line: "This is `a` test", 56 what: "a", 57 expected: true, 58 }, 59 } 60 61 for _, tt := range tests { 62 t.Run(tt.line, func(t *testing.T) { 63 if got := withinBackticks(tt.line, tt.what); got != tt.expected { 64 t.Errorf("withinBackticks(%q, %q) = %v; expected %v", tt.line, tt.what, got, tt.expected) 65 } 66 }) 67 } 68 }