blob: 1773b01d125a202c2c402f292ea678ab5bb3c44d [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package parser_test
import (
"testing"
"android.googlesource.com/platform/tools/gpu/api/parser"
"android.googlesource.com/platform/tools/gpu/framework/assert"
"android.googlesource.com/platform/tools/gpu/framework/parse"
"android.googlesource.com/platform/tools/gpu/framework/parse/test"
)
var (
B = test.Branch
L = test.Leaf
N = test.Node
)
func TestParsedCST(t *testing.T) {
ctx := assert.Context(t)
for _, test := range []struct {
name string
expected parse.Node
source string
errors parse.ErrorList
}{
{
name: "const int*",
source: `const int* a`,
expected: B(B(
N(nil, B(
N(nil, "const", " "),
B(B(L("int")), L("*")),
), " ",
),
L("a"),
)),
},
{
name: "const char* const *",
source: `const char* const * a`,
expected: B(B(
B(
N(nil, B(
N(nil, "const", " "),
B(
B(L("char")),
L("*"),
),
), " "),
N(nil, L("const"), " "),
N(nil, L("*"), " "),
),
L("a"),
)),
},
} {
ctx := ctx.S("Name", test.name)
m := parser.NewParseMap()
api, errs := parser.Parse("parser_test.api", test.source, m)
assert.With(ctx).ThatSlice(errs).Equals(test.errors)
assert.With(ctx).That(m.CST(api)).DeepEquals(test.expected)
}
}