blob: ac5a76a170140e0d6149044146eeda0fb32b9abd [file] [log] [blame]
Marcel van Lohuizen17157ea2018-12-11 10:41:10 +01001// Copyright 2018 The 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
15package cue
16
17import (
18 "fmt"
19 "testing"
20)
21
22func TestMatchBinOpKind(t *testing.T) {
23 testCases := []struct {
24 op op
25 a kind
26 b kind
27 want kind
28 }{{
29 op: opMul,
30 a: floatKind,
Marcel van Lohuizen0a7717d2019-02-13 17:36:32 +040031 b: numKind,
Marcel van Lohuizen17157ea2018-12-11 10:41:10 +010032 want: floatKind,
33 }, {
34 op: opMul,
Marcel van Lohuizen0a7717d2019-02-13 17:36:32 +040035 a: intKind,
36 b: numKind,
37 want: intKind,
38 }, {
39 op: opMul,
40 a: floatKind,
41 b: intKind,
Marcel van Lohuizen4a360992019-05-11 18:18:31 +020042 want: floatKind,
Marcel van Lohuizen0a7717d2019-02-13 17:36:32 +040043 }, {
44 op: opMul,
Marcel van Lohuizen17157ea2018-12-11 10:41:10 +010045 a: listKind,
46 b: intKind,
47 want: listKind,
48 }, {
49 op: opMul,
50 a: intKind,
51 b: listKind,
52 want: listKind,
53 }}
54 for _, tc := range testCases {
55 key := fmt.Sprintf("%s(%v, %v)", tc.op, tc.a, tc.b)
56 t.Run(key, func(t *testing.T) {
57 got, _ := matchBinOpKind(tc.op, tc.a, tc.b)
58 if got != tc.want {
59 t.Errorf("got %v, want %v", got, tc.want)
60 }
61 })
62 }
63}