Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing implemented with all tests passing! 🎉 #25

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7ece032
Renamed output executable in main CMakeLists file!
hrszpuk Jan 6, 2025
1d23880
Deleted parser_test.cpp (re-organising tests)
hrszpuk Jan 6, 2025
a36c5a9
tests/CMakeLists.txt now tests all files in tests/parser/*.cpp
hrszpuk Jan 6, 2025
b9a1a2b
Added expression tests for parsing
hrszpuk Jan 6, 2025
a3c2f48
Added variable declaration tests for parsing
hrszpuk Jan 6, 2025
b61c6a4
Added variable assignment tests for parsing
hrszpuk Jan 6, 2025
fb0dc69
Added for loop tests for parsing
hrszpuk Jan 6, 2025
8ee0ea6
Added function call tests for parsing
hrszpuk Jan 6, 2025
d4955ac
Added if else tests for parsing
hrszpuk Jan 6, 2025
c96afe6
Added while loop tests for parsing
hrszpuk Jan 6, 2025
d37e682
Added some full program test files for more extensive future tests
hrszpuk Jan 6, 2025
6e5953d
Merge pull request #22 from dragonfly-lang/7-create-tests-for-the-parser
hrszpuk Jan 6, 2025
c2efa18
Added Node class (parent to all nodes)
hrszpuk Jan 6, 2025
6bebcc8
Added ExpressionNode and StatementNode
hrszpuk Jan 6, 2025
6b7a801
Added skeleton nodes for for loops
hrszpuk Jan 6, 2025
ac0f9bd
Added skeleton nodes for function calls
hrszpuk Jan 6, 2025
867b580
Added skeleton nodes for identifiers
hrszpuk Jan 6, 2025
b29a37e
Added skeleton nodes for if-else statements
hrszpuk Jan 6, 2025
626afc1
Added skeleton nodes for literal node
hrszpuk Jan 6, 2025
c40ac01
Added skeleton nodes for while loops
hrszpuk Jan 6, 2025
3faf1f6
Added skeleton nodes for variable assignment
hrszpuk Jan 6, 2025
6e313e0
Added node skeleton for variable declarations
hrszpuk Jan 6, 2025
e61f35b
Added attributes, constructor, destructor, and to_string to variable …
hrszpuk Jan 6, 2025
5e9dbcf
Merge pull request #23 from dragonfly-lang/8-set-up-ast-and-nodes-for…
hrszpuk Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added if else tests for parsing
hrszpuk committed Jan 6, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit d4955ac79f79508c1dbf9ff70f3540fff7012c88
32 changes: 32 additions & 0 deletions tests/parser/if_else.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <gtest/gtest.h>

#include "dragon/parser.h"
#include "dragon/token.h"
#include "dragon/lexer.h"

struct IfElseTestParam {
std::string code;
std::string to_string_result;
};

class IfElseTests : public ::testing::TestWithParam<IfElseTestParam> {};

TEST_P(IfElseTests, HandlesIfElse) {
IfElseTestParam param = GetParam();

Parser parser(Lexer(param.code).lex());
auto nodes = parser.parse();

EXPECT_EQ(nodes[0].to_string(), param.to_string_result) << "Expected " << param.to_string_result << ", got " << nodes[0].to_string();
}

INSTANTIATE_TEST_SUITE_P(
IfElseVariations,
IfElseTests,
::testing::Values(
IfElseTestParam{"if true { print(5) }", "IfElseNode"},
IfElseTestParam{"if true==true { print(5) } else { print(10) }", "IfElseNode"},
IfElseTestParam{"if true { print(5) } else if false { print(10) }", "IfElseNode"},
IfElseTestParam{"if true { print(5) } else if false { print(10) } else { print(15) }", "IfElseNode"}
)
);