| 1 |
// Copyright (c) 2018-2022, Maxime Soulé |
| 2 |
// All rights reserved. |
| 3 |
// |
| 4 |
// This source code is licensed under the BSD-style license found in the |
| 5 |
// LICENSE file in the root directory of this source tree. |
| 6 |
|
| 7 |
package td_test |
| 8 |
|
| 9 |
import ( |
| 10 |
"testing" |
| 11 |
|
| 12 |
"github.com/maxatome/go-testdeep/internal/test" |
| 13 |
"github.com/maxatome/go-testdeep/td" |
| 14 |
) |
| 15 |
|
| 16 |
func TestNone(t *testing.T) { |
| 17 |
checkOK(t, 6, td.None(7, 8, 9, nil)) |
| 18 |
checkOK(t, nil, td.None(7, 8, 9)) |
| 19 |
|
| 20 |
checkError(t, 6, td.None(6, 7), |
| 21 |
expectedError{ |
| 22 |
Message: mustBe("comparing with None (part 1 of 2 is OK)"), |
| 23 |
Path: mustBe("DATA"), |
| 24 |
Got: mustBe("6"), |
| 25 |
Expected: mustBe("None(6,\n 7)"), |
| 26 |
}) |
| 27 |
|
| 28 |
checkError(t, nil, td.None(7, nil), |
| 29 |
expectedError{ |
| 30 |
Message: mustBe("comparing with None (part 2 of 2 is OK)"), |
| 31 |
Path: mustBe("DATA"), |
| 32 |
Got: mustBe("nil"), |
| 33 |
Expected: mustBe("None(7,\n nil)"), |
| 34 |
}) |
| 35 |
|
| 36 |
// Lax |
| 37 |
checkError(t, float64(6), td.Lax(td.None(6, 7)), |
| 38 |
expectedError{ |
| 39 |
Message: mustBe("comparing with None (part 1 of 2 is OK)"), |
| 40 |
Path: mustBe("DATA"), |
| 41 |
Got: mustBe("6.0"), |
| 42 |
Expected: mustBe("None(6,\n 7)"), |
| 43 |
}) |
| 44 |
|
| 45 |
checkError(t, 123, td.None(1, td.JSON("{")), |
| 46 |
expectedError{ |
| 47 |
Message: mustBe("bad usage of JSON operator"), |
| 48 |
Path: mustBe(`DATA`), |
| 49 |
Summary: mustContain("JSON unmarshal error"), |
| 50 |
Under: mustContain("under operator JSON at "), |
| 51 |
}, |
| 52 |
"erroneous operator expected") |
| 53 |
|
| 54 |
// |
| 55 |
// String |
| 56 |
test.EqualStr(t, td.None(6).String(), "None(6)") |
| 57 |
test.EqualStr(t, td.None(6, 7).String(), "None(6,\n 7)") |
| 58 |
} |
| 59 |
|
| 60 |
func TestNot(t *testing.T) { |
| 61 |
checkOK(t, 6, td.Not(7)) |
| 62 |
checkOK(t, nil, td.Not(7)) |
| 63 |
|
| 64 |
checkError(t, 6, td.Not(6), |
| 65 |
expectedError{ |
| 66 |
Message: mustBe("comparing with Not"), |
| 67 |
Path: mustBe("DATA"), |
| 68 |
Got: mustBe("6"), |
| 69 |
Expected: mustBe("Not(6)"), |
| 70 |
}) |
| 71 |
|
| 72 |
checkError(t, nil, td.Not(nil), |
| 73 |
expectedError{ |
| 74 |
Message: mustBe("comparing with Not"), |
| 75 |
Path: mustBe("DATA"), |
| 76 |
Got: mustBe("nil"), |
| 77 |
Expected: mustBe("Not(nil)"), |
| 78 |
}) |
| 79 |
|
| 80 |
checkError(t, 123, td.Not(td.JSON("{")), |
| 81 |
expectedError{ |
| 82 |
Message: mustBe("bad usage of JSON operator"), |
| 83 |
Path: mustBe(`DATA`), |
| 84 |
Summary: mustContain("JSON unmarshal error"), |
| 85 |
Under: mustContain("under operator JSON at "), |
| 86 |
}, |
| 87 |
"erroneous operator expected") |
| 88 |
|
| 89 |
// |
| 90 |
// String |
| 91 |
test.EqualStr(t, td.Not(6).String(), "Not(6)") |
| 92 |
} |
| 93 |
|
| 94 |
func TestNoneTypeBehind(t *testing.T) { |
| 95 |
equalTypes(t, td.None(6), nil) |
| 96 |
equalTypes(t, td.Not(6), nil) |
| 97 |
} |