• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Amber 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 parseried.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/amberscript/parser.h"
16 
17 #include "gtest/gtest.h"
18 
19 namespace amber {
20 namespace amberscript {
21 
22 using AmberScriptParserTest = testing::Test;
23 
TEST_F(AmberScriptParserTest,EmptyInput)24 TEST_F(AmberScriptParserTest, EmptyInput) {
25   std::string in = "";
26 
27   Parser parser;
28   Result r = parser.Parse(in);
29   ASSERT_TRUE(r.IsSuccess()) << r.Error();
30 
31   auto script = parser.GetScript();
32   ASSERT_TRUE(script != nullptr);
33 }
34 
TEST_F(AmberScriptParserTest,InvalidStartToken)35 TEST_F(AmberScriptParserTest, InvalidStartToken) {
36   std::string in = R"(#!amber
37 # Start comment
38 1234)";
39 
40   Parser parser;
41   Result r = parser.Parse(in);
42   ASSERT_FALSE(r.IsSuccess());
43   EXPECT_EQ("3: expected identifier", r.Error());
44 }
45 
TEST_F(AmberScriptParserTest,UnknownStartToken)46 TEST_F(AmberScriptParserTest, UnknownStartToken) {
47   std::string in = "INVALID token";
48 
49   Parser parser;
50   Result r = parser.Parse(in);
51   ASSERT_FALSE(r.IsSuccess());
52   EXPECT_EQ("1: unknown token: INVALID", r.Error());
53 }
54 
55 }  // namespace amberscript
56 }  // namespace amber
57