Marcel van Lohuizen | 6a08830 | 2020-07-03 14:42:05 +0200 | [diff] [blame] | 1 | // Copyright 2020 CUE Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package adt |
| 16 | |
| 17 | import "testing" |
| 18 | |
| 19 | func TestKindString(t *testing.T) { |
| 20 | testCases := []struct { |
| 21 | input Kind |
| 22 | want string |
| 23 | }{{ |
| 24 | input: BottomKind, |
| 25 | want: "_|_", |
| 26 | }, { |
| 27 | input: IntKind | ListKind, |
| 28 | want: `(int|[...])`, |
| 29 | }, { |
| 30 | input: NullKind, |
| 31 | want: "null", |
| 32 | }, { |
| 33 | input: IntKind, |
| 34 | want: "int", |
| 35 | }, { |
| 36 | input: FloatKind, |
| 37 | want: "float", |
| 38 | }, { |
| 39 | input: StringKind, |
| 40 | want: "string", |
| 41 | }, { |
| 42 | input: BytesKind, |
| 43 | want: "bytes", |
| 44 | }, { |
| 45 | input: StructKind, |
| 46 | want: "{...}", |
| 47 | }, { |
| 48 | input: ListKind, |
| 49 | want: "[...]", |
| 50 | }, { |
| 51 | input: NumberKind, |
| 52 | want: "number", |
| 53 | }, { |
| 54 | input: BoolKind | NumberKind | ListKind, |
| 55 | want: "(bool|[...]|number)", |
| 56 | }, { |
| 57 | input: 1 << 15, |
| 58 | want: "bad(15)", |
| 59 | }} |
| 60 | for _, tc := range testCases { |
| 61 | t.Run(tc.want, func(t *testing.T) { |
| 62 | got := tc.input.TypeString() |
| 63 | if got != tc.want { |
| 64 | t.Errorf("\n got %v;\nwant %v", got, tc.want) |
| 65 | } |
| 66 | }) |
| 67 | } |
| 68 | } |