File: test_precedence.cpp

package info (click to toggle)
libpog 0.5.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,644 kB
  • sloc: cpp: 51,038; ansic: 239; makefile: 14; python: 11; sh: 11
file content (81 lines) | stat: -rw-r--r-- 1,950 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <gtest/gtest.h>

#include <pog/precedence.h>

class TestPrecedence : public ::testing::Test {};

using namespace pog;

TEST_F(TestPrecedence,
Equality) {
	Precedence p1{1, Associativity::Left};
	Precedence p2{1, Associativity::Left};
	Precedence p3{1, Associativity::Right};
	Precedence p4{0, Associativity::Left};
	Precedence p5{2, Associativity::Left};

	EXPECT_EQ(p1, p2);
	EXPECT_NE(p1, p3);
	EXPECT_NE(p1, p4);
	EXPECT_NE(p1, p5);
}

TEST_F(TestPrecedence,
SameLevelLeftAssociative) {
	EXPECT_FALSE(
		(Precedence{1, Associativity::Left}) < (Precedence{1, Associativity::Left})
	);
	EXPECT_TRUE(
		(Precedence{1, Associativity::Left}) > (Precedence{1, Associativity::Left})
	);
}

TEST_F(TestPrecedence,
SameLevelRightAssociative) {
	EXPECT_TRUE(
		(Precedence{1, Associativity::Right}) < (Precedence{1, Associativity::Right})
	);
	EXPECT_FALSE(
		(Precedence{1, Associativity::Right}) > (Precedence{1, Associativity::Right})
	);
}

TEST_F(TestPrecedence,
LowerLevelLeftAssociative) {
	EXPECT_TRUE(
		(Precedence{0, Associativity::Left}) < (Precedence{1, Associativity::Left})
	);
	EXPECT_FALSE(
		(Precedence{0, Associativity::Left}) > (Precedence{1, Associativity::Left})
	);
}

TEST_F(TestPrecedence,
LowerLevelRightAssociative) {
	EXPECT_TRUE(
		(Precedence{0, Associativity::Right}) < (Precedence{1, Associativity::Right})
	);
	EXPECT_FALSE(
		(Precedence{0, Associativity::Right}) > (Precedence{1, Associativity::Right})
	);
}

TEST_F(TestPrecedence,
HigherLevelLeftAssociative) {
	EXPECT_FALSE(
		(Precedence{2, Associativity::Left}) < (Precedence{1, Associativity::Left})
	);
	EXPECT_TRUE(
		(Precedence{2, Associativity::Left}) > (Precedence{1, Associativity::Left})
	);
}

TEST_F(TestPrecedence,
HigherLevelRightAssociative) {
	EXPECT_FALSE(
		(Precedence{2, Associativity::Right}) < (Precedence{1, Associativity::Right})
	);
	EXPECT_TRUE(
		(Precedence{2, Associativity::Right}) > (Precedence{1, Associativity::Right})
	);
}