1package assertions 2 3import "testing" 4 5func TestShouldStartWith(t *testing.T) { 6 serializer = newFakeSerializer() 7 8 fail(t, so("", ShouldStartWith), "This assertion requires exactly 1 comparison values (you provided 0).") 9 fail(t, so("", ShouldStartWith, "asdf", "asdf"), "This assertion requires exactly 1 comparison values (you provided 2).") 10 11 pass(t, so("", ShouldStartWith, "")) 12 fail(t, so("", ShouldStartWith, "x"), "x||Expected '' to start with 'x' (but it didn't)!") 13 pass(t, so("abc", ShouldStartWith, "abc")) 14 fail(t, so("abc", ShouldStartWith, "abcd"), "abcd|abc|Expected 'abc' to start with 'abcd' (but it didn't)!") 15 16 pass(t, so("superman", ShouldStartWith, "super")) 17 fail(t, so("superman", ShouldStartWith, "bat"), "bat|sup...|Expected 'superman' to start with 'bat' (but it didn't)!") 18 fail(t, so("superman", ShouldStartWith, "man"), "man|sup...|Expected 'superman' to start with 'man' (but it didn't)!") 19 20 fail(t, so(1, ShouldStartWith, 2), "Both arguments to this assertion must be strings (you provided int and int).") 21} 22 23func TestShouldNotStartWith(t *testing.T) { 24 fail(t, so("", ShouldNotStartWith), "This assertion requires exactly 1 comparison values (you provided 0).") 25 fail(t, so("", ShouldNotStartWith, "asdf", "asdf"), "This assertion requires exactly 1 comparison values (you provided 2).") 26 27 fail(t, so("", ShouldNotStartWith, ""), "Expected '<empty>' NOT to start with '<empty>' (but it did)!") 28 fail(t, so("superman", ShouldNotStartWith, "super"), "Expected 'superman' NOT to start with 'super' (but it did)!") 29 pass(t, so("superman", ShouldNotStartWith, "bat")) 30 pass(t, so("superman", ShouldNotStartWith, "man")) 31 32 fail(t, so(1, ShouldNotStartWith, 2), "Both arguments to this assertion must be strings (you provided int and int).") 33} 34 35func TestShouldEndWith(t *testing.T) { 36 serializer = newFakeSerializer() 37 38 fail(t, so("", ShouldEndWith), "This assertion requires exactly 1 comparison values (you provided 0).") 39 fail(t, so("", ShouldEndWith, "", ""), "This assertion requires exactly 1 comparison values (you provided 2).") 40 41 pass(t, so("", ShouldEndWith, "")) 42 fail(t, so("", ShouldEndWith, "z"), "z||Expected '' to end with 'z' (but it didn't)!") 43 pass(t, so("xyz", ShouldEndWith, "xyz")) 44 fail(t, so("xyz", ShouldEndWith, "wxyz"), "wxyz|xyz|Expected 'xyz' to end with 'wxyz' (but it didn't)!") 45 46 pass(t, so("superman", ShouldEndWith, "man")) 47 fail(t, so("superman", ShouldEndWith, "super"), "super|...erman|Expected 'superman' to end with 'super' (but it didn't)!") 48 fail(t, so("superman", ShouldEndWith, "blah"), "blah|...rman|Expected 'superman' to end with 'blah' (but it didn't)!") 49 50 fail(t, so(1, ShouldEndWith, 2), "Both arguments to this assertion must be strings (you provided int and int).") 51} 52 53func TestShouldNotEndWith(t *testing.T) { 54 fail(t, so("", ShouldNotEndWith), "This assertion requires exactly 1 comparison values (you provided 0).") 55 fail(t, so("", ShouldNotEndWith, "", ""), "This assertion requires exactly 1 comparison values (you provided 2).") 56 57 fail(t, so("", ShouldNotEndWith, ""), "Expected '<empty>' NOT to end with '<empty>' (but it did)!") 58 fail(t, so("superman", ShouldNotEndWith, "man"), "Expected 'superman' NOT to end with 'man' (but it did)!") 59 pass(t, so("superman", ShouldNotEndWith, "super")) 60 61 fail(t, so(1, ShouldNotEndWith, 2), "Both arguments to this assertion must be strings (you provided int and int).") 62} 63 64func TestShouldContainSubstring(t *testing.T) { 65 serializer = newFakeSerializer() 66 67 fail(t, so("asdf", ShouldContainSubstring), "This assertion requires exactly 1 comparison values (you provided 0).") 68 fail(t, so("asdf", ShouldContainSubstring, 1, 2, 3), "This assertion requires exactly 1 comparison values (you provided 3).") 69 70 fail(t, so(123, ShouldContainSubstring, 23), "Both arguments to this assertion must be strings (you provided int and int).") 71 72 pass(t, so("asdf", ShouldContainSubstring, "sd")) 73 fail(t, so("qwer", ShouldContainSubstring, "sd"), "sd|qwer|Expected 'qwer' to contain substring 'sd' (but it didn't)!") 74} 75 76func TestShouldNotContainSubstring(t *testing.T) { 77 fail(t, so("asdf", ShouldNotContainSubstring), "This assertion requires exactly 1 comparison values (you provided 0).") 78 fail(t, so("asdf", ShouldNotContainSubstring, 1, 2, 3), "This assertion requires exactly 1 comparison values (you provided 3).") 79 80 fail(t, so(123, ShouldNotContainSubstring, 23), "Both arguments to this assertion must be strings (you provided int and int).") 81 82 pass(t, so("qwer", ShouldNotContainSubstring, "sd")) 83 fail(t, so("asdf", ShouldNotContainSubstring, "sd"), "Expected 'asdf' NOT to contain substring 'sd' (but it did)!") 84} 85 86func TestShouldBeBlank(t *testing.T) { 87 serializer = newFakeSerializer() 88 89 fail(t, so("", ShouldBeBlank, "adsf"), "This assertion requires exactly 0 comparison values (you provided 1).") 90 fail(t, so(1, ShouldBeBlank), "The argument to this assertion must be a string (you provided int).") 91 92 fail(t, so("asdf", ShouldBeBlank), "|asdf|Expected 'asdf' to be blank (but it wasn't)!") 93 pass(t, so("", ShouldBeBlank)) 94} 95 96func TestShouldNotBeBlank(t *testing.T) { 97 fail(t, so("", ShouldNotBeBlank, "adsf"), "This assertion requires exactly 0 comparison values (you provided 1).") 98 fail(t, so(1, ShouldNotBeBlank), "The argument to this assertion must be a string (you provided int).") 99 100 fail(t, so("", ShouldNotBeBlank), "Expected value to NOT be blank (but it was)!") 101 pass(t, so("asdf", ShouldNotBeBlank)) 102} 103 104func TestShouldEqualWithout(t *testing.T) { 105 fail(t, so("", ShouldEqualWithout, ""), "This assertion requires exactly 2 comparison values (you provided 1).") 106 fail(t, so(1, ShouldEqualWithout, 2, 3), "All arguments to this assertion must be strings (you provided: [int int int]).") 107 108 fail(t, so("asdf", ShouldEqualWithout, "qwer", "q"), "Expected 'asdf' to equal 'qwer' but without any 'q' (but it didn't).") 109 pass(t, so("asdf", ShouldEqualWithout, "df", "as")) 110} 111 112func TestShouldEqualTrimSpace(t *testing.T) { 113 fail(t, so(" asdf ", ShouldEqualTrimSpace), "This assertion requires exactly 1 comparison values (you provided 0).") 114 fail(t, so(1, ShouldEqualTrimSpace, 2), "Both arguments to this assertion must be strings (you provided int and int).") 115 116 fail(t, so("asdf", ShouldEqualTrimSpace, "qwer"), "qwer|asdf|Expected: 'qwer' Actual: 'asdf' (Should be equal)") 117 pass(t, so(" asdf\t\n", ShouldEqualTrimSpace, "asdf")) 118} 119