1// Copyright 2018 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <unittest/unittest.h> 6 7#include <fidl/flat_ast.h> 8#include <fidl/lexer.h> 9#include <fidl/parser.h> 10#include <fidl/source_file.h> 11 12#include "test_library.h" 13 14namespace { 15 16// Test that a duplicate attribute is caught, and nicely reported. 17bool no_two_same_attribute_test() { 18 BEGIN_TEST; 19 20 TestLibrary library("dup_attributes.fidl", R"FIDL( 21library fidl.test.dupattributes; 22 23[dup = "first", dup = "second"] 24interface A { 25 1: MethodA(); 26}; 27 28)FIDL"); 29 EXPECT_FALSE(library.Compile()); 30 auto errors = library.errors(); 31 ASSERT_EQ(errors.size(), 1); 32 ASSERT_STR_STR(errors[0].c_str(), "Duplicate attribute with name 'dup'"); 33 34 END_TEST; 35} 36 37// Test that doc comments and doc attributes clash are properly checked. 38bool no_two_same_doc_attribute_test() { 39 BEGIN_TEST; 40 41 TestLibrary library("dup_attributes.fidl", R"FIDL( 42library fidl.test.dupattributes; 43 44/// first 45[Doc = "second"] 46interface A { 47 1: MethodA(); 48}; 49 50)FIDL"); 51 EXPECT_FALSE(library.Compile()); 52 auto errors = library.errors(); 53 ASSERT_EQ(errors.size(), 1); 54 ASSERT_STR_STR(errors[0].c_str(), "Duplicate attribute with name 'Doc'"); 55 56 END_TEST; 57} 58 59// Test that TODO 60bool no_two_same_attribute_on_library_test() { 61 BEGIN_TEST; 62 63 TestLibrary library("dup_attributes.fidl", R"FIDL( 64[dup = "first"] 65library fidl.test.dupattributes; 66 67)FIDL"); 68 EXPECT_TRUE(library.Compile()); 69 70 EXPECT_FALSE(library.AddSourceFile("dup_attributes_second.fidl", R"FIDL( 71[dup = "second"] 72library fidl.test.dupattributes; 73 74)FIDL")); 75 auto errors = library.errors(); 76 ASSERT_EQ(errors.size(), 1); 77 ASSERT_STR_STR(errors[0].c_str(), "Duplicate attribute with name 'dup'"); 78 79 END_TEST; 80} 81 82 83} // namespace 84 85BEGIN_TEST_CASE(dup_attributes_tests); 86RUN_TEST(no_two_same_attribute_test); 87RUN_TEST(no_two_same_doc_attribute_test); 88RUN_TEST(no_two_same_attribute_on_library_test); 89END_TEST_CASE(dup_attributes_tests); 90