Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
878216c3
Commit
878216c3
authored
Nov 4, 2019
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Complete tests for SymbolTable
parent
cb004f33
No related branches found
No related tags found
1 merge request
!37
Feature/language
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_SymbolTable.cpp
+90
-0
90 additions, 0 deletions
tests/test_SymbolTable.cpp
with
90 additions
and
0 deletions
tests/test_SymbolTable.cpp
+
90
−
0
View file @
878216c3
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include
<SymbolTable.hpp>
#include
<SymbolTable.hpp>
#include
<sstream>
#include
<sstream>
#include
<CFunctionEmbedder.hpp>
#include
<pegtl/internal/iterator.hpp>
#include
<pegtl/internal/iterator.hpp>
TEST_CASE
(
"SymbolTable"
,
"[language]"
)
TEST_CASE
(
"SymbolTable"
,
"[language]"
)
...
@@ -127,4 +129,92 @@ TEST_CASE("SymbolTable", "[language]")
...
@@ -127,4 +129,92 @@ TEST_CASE("SymbolTable", "[language]")
auto
[
i_search_b
,
found_b
]
=
nested_st
->
find
(
"b"
,
use_position
);
auto
[
i_search_b
,
found_b
]
=
nested_st
->
find
(
"b"
,
use_position
);
REQUIRE
(
not
found_b
);
// "b" is not defined in any symbol table
REQUIRE
(
not
found_b
);
// "b" is not defined in any symbol table
}
}
SECTION
(
"Output of function_id"
)
{
std
::
shared_ptr
root_st
=
std
::
make_shared
<
SymbolTable
>
();
using
namespace
TAO_PEGTL_NAMESPACE
;
position
begin_position
{
internal
::
iterator
{
"fixture"
},
"fixture"
};
begin_position
.
byte
=
2
;
auto
[
i_symbol_a
,
created_a
]
=
root_st
->
add
(
"a"
,
begin_position
);
REQUIRE
(
i_symbol_a
->
attributes
().
position
().
byte
==
2
);
position
use_position
{
internal
::
iterator
{
"fixture"
},
"fixture"
};
use_position
.
byte
=
3
;
// after declarative position
auto
[
i_search_a
,
found_a
]
=
root_st
->
find
(
"a"
,
use_position
);
REQUIRE
(
found_a
);
REQUIRE
(
i_search_a
==
i_symbol_a
);
auto
&
attributes_a
=
i_search_a
->
attributes
();
REQUIRE
(
attributes_a
.
dataType
()
==
ASTNodeDataType
::
undefined_t
);
REQUIRE
(
not
attributes_a
.
isInitialized
());
REQUIRE
(
std
::
holds_alternative
<
std
::
monostate
>
(
attributes_a
.
value
()));
{
std
::
stringstream
value_output
;
value_output
<<
attributes_a
;
REQUIRE
(
value_output
.
str
()
==
"--"
);
}
// defining function data
attributes_a
.
setIsInitialized
();
REQUIRE
(
attributes_a
.
isInitialized
());
attributes_a
.
setDataType
(
ASTNodeDataType
::
function_t
);
REQUIRE
(
attributes_a
.
dataType
()
==
ASTNodeDataType
::
function_t
);
attributes_a
.
value
()
=
static_cast
<
uint64_t
>
(
2
);
REQUIRE
(
std
::
holds_alternative
<
uint64_t
>
(
attributes_a
.
value
()));
{
std
::
stringstream
value_output
;
value_output
<<
attributes_a
;
REQUIRE
(
value_output
.
str
()
==
"function_id:2"
);
}
{
const
SymbolTable
::
Symbol
symbol
{
i_symbol_a
->
name
(),
i_symbol_a
->
attributes
()};
std
::
stringstream
value_output
;
value_output
<<
symbol
.
attributes
();
REQUIRE
(
value_output
.
str
()
==
"function_id:2"
);
}
}
SECTION
(
"FunctionTable"
)
{
std
::
shared_ptr
root_st
=
std
::
make_shared
<
SymbolTable
>
();
auto
&
function_table
=
root_st
->
functionTable
();
REQUIRE
(
function_table
.
size
()
==
0
);
const
auto
&
const_function_table
=
static_cast
<
const
SymbolTable
&>
(
*
root_st
).
functionTable
();
REQUIRE
(
const_function_table
.
size
()
==
0
);
function_table
.
add
(
FunctionDescriptor
{});
REQUIRE
(
function_table
.
size
()
==
1
);
REQUIRE
(
const_function_table
.
size
()
==
1
);
}
SECTION
(
"CFunctionEmbedderTable"
)
{
std
::
shared_ptr
root_st
=
std
::
make_shared
<
SymbolTable
>
();
auto
&
c_function_table
=
root_st
->
cFunctionEbedderTable
();
REQUIRE
(
c_function_table
.
size
()
==
0
);
const
auto
&
const_c_function_table
=
static_cast
<
const
SymbolTable
&>
(
*
root_st
).
cFunctionEbedderTable
();
REQUIRE
(
const_c_function_table
.
size
()
==
0
);
c_function_table
.
add
(
std
::
make_shared
<
CFunctionEmbedder
<
double
,
double
>>
(
std
::
function
<
double
(
double
)
>
{[](
double
)
->
double
{
return
0
;
}}));
REQUIRE
(
c_function_table
.
size
()
==
1
);
REQUIRE
(
const_c_function_table
.
size
()
==
1
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment