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// Copyright 2018 The Fuchsia Authors. All rights reserved.
6// Use of this source code is governed by a BSD-style license that can be
7// found in the LICENSE file.
8
9#include <regex>
10#include <unittest/unittest.h>
11
12#include <fidl/flat_ast.h>
13
14namespace {
15
16using fidl::flat::HandleType;
17using fidl::types::HandleSubtype;
18using fidl::types::Nullability;
19
20static bool implicit_assumptions() {
21    // Preconditions to unit test cases: if these change, we need to rewrite the tests themselves.
22    EXPECT_TRUE(HandleSubtype::kChannel < HandleSubtype::kEvent);
23    EXPECT_TRUE(Nullability::kNullable < Nullability::kNonnullable);
24
25    return true;
26}
27
28static bool compare_handles() {
29    HandleType nonnullable_channel(HandleSubtype::kChannel, Nullability::kNonnullable);
30    HandleType nullable_channel(HandleSubtype::kChannel, Nullability::kNullable);
31    HandleType nonnullable_event(HandleSubtype::kEvent, Nullability::kNonnullable);
32    HandleType nullable_event(HandleSubtype::kEvent, Nullability::kNullable);
33
34    // Comparison is nullability, then type.
35    EXPECT_TRUE(nullable_channel < nonnullable_channel);
36    EXPECT_TRUE(nullable_event < nonnullable_event);
37    EXPECT_TRUE(nonnullable_channel < nonnullable_event);
38    EXPECT_TRUE(nullable_channel < nullable_event);
39
40    return true;
41}
42
43} // namespace
44
45BEGIN_TEST_CASE(flat_ast_tests);
46RUN_TEST(implicit_assumptions);
47RUN_TEST(compare_handles);
48END_TEST_CASE(flat_ast_tests);
49