-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatusTest.cpp
More file actions
58 lines (50 loc) · 1.66 KB
/
StatusTest.cpp
File metadata and controls
58 lines (50 loc) · 1.66 KB
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
// This file is subject to the terms and conditions defined in file 'LICENSE', which is part of this source code.
// Copyright (C) 2019 Silas B. Domingos
// All rights reserved.
//
#include "CppUnitTest.h"
#include "../../Library/Source/Proyth.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Proyth;
using namespace Proyth::Rules;
namespace ProythTest
{
TEST_CLASS(StatusTest)
{
public:
TEST_METHOD(FailureTest)
{
char chars[] = "AB";
Node<char>* tree = nullptr;
Context<char> context(chars, tree);
Status::Failure<Char::Expect>::Pack<char> rule(0xA0, { 'A' });
// Consume character 'A'
Assert::IsTrue(rule.consume(context));
Assert::IsFalse(context.hasError());
Assert::AreEqual(1U, context.getOffset());
// Can't consume character 'B' and fail
Assert::IsFalse(rule.consume(context));
Assert::IsTrue(context.hasError());
Assert::AreEqual(1U, context.getError().getOffset());
Assert::AreEqual(0xA0, context.getError().getCode());
Assert::AreEqual(1U, context.getOffset());
}
TEST_METHOD(SuccessTest)
{
char chars[] = "AB";
Node<char>* tree = nullptr;
Context<char> context(chars, tree);
Status::Success<Char::Expect>::Pack<char> rule({ 'B' });
// Can't consume character 'A' and fail
Assert::IsFalse(Status::Failure<Char::Expect>::Pack<char>(0xA0, { 'B' }).consume(context));
Assert::IsTrue(context.hasError());
Assert::AreEqual(0U, context.getOffset());
// Skip character 'A'
context.forward(1);
// Consume character 'B' and succeed
Assert::IsTrue(rule.consume(context));
Assert::IsFalse(context.hasError());
Assert::AreEqual(2U, context.getOffset());
}
};
}