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
39c4ed0b
Commit
39c4ed0b
authored
Jan 10, 2020
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add missing tests for ASTSymbolInitializationChecker
parent
9708c7ec
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_ASTSymbolInitializationChecker.cpp
+96
-3
96 additions, 3 deletions
tests/test_ASTSymbolInitializationChecker.cpp
with
96 additions
and
3 deletions
tests/test_ASTSymbolInitializationChecker.cpp
+
96
−
3
View file @
39c4ed0b
...
...
@@ -69,7 +69,7 @@ m = n;
REQUIRE
(
not
symbol_z
->
attributes
().
isInitialized
());
}
SECTION
(
"Declarative initialization"
)
SECTION
(
"Declarative
function
initialization"
)
{
std
::
string_view
data
=
R"(
let f: R->R, x->x+1;
...
...
@@ -89,6 +89,83 @@ let f: R->R, x->x+1;
REQUIRE
(
symbol_m
->
attributes
().
isInitialized
());
}
SECTION
(
"Lists"
)
{
SECTION
(
"Declarative initialization"
)
{
std
::
string_view
data
=
R"(
R*R (x,y) = (2.3, 4.1);
)"
;
string_input
input
{
data
,
"test.pgs"
};
auto
ast
=
ASTBuilder
::
build
(
input
);
ASTSymbolTableBuilder
{
*
ast
};
ASTSymbolInitializationChecker
{
*
ast
};
position
position
{
internal
::
iterator
{
"fixture"
},
"fixture"
};
position
.
byte
=
data
.
size
();
// ensure that variables are declared at this point
auto
[
symbol_x
,
found_x
]
=
ast
->
m_symbol_table
->
find
(
"x"
,
position
);
REQUIRE
(
found_x
);
REQUIRE
(
symbol_x
->
attributes
().
isInitialized
());
auto
[
symbol_y
,
found_y
]
=
ast
->
m_symbol_table
->
find
(
"y"
,
position
);
REQUIRE
(
found_y
);
REQUIRE
(
symbol_y
->
attributes
().
isInitialized
());
}
SECTION
(
"Not initialized"
)
{
std
::
string_view
data
=
R"(
R*R (x,y);
y = 3;
)"
;
string_input
input
{
data
,
"test.pgs"
};
auto
ast
=
ASTBuilder
::
build
(
input
);
ASTSymbolTableBuilder
{
*
ast
};
ASTSymbolInitializationChecker
{
*
ast
};
position
position
{
internal
::
iterator
{
"fixture"
},
"fixture"
};
position
.
byte
=
data
.
size
();
// ensure that variables are declared at this point
auto
[
symbol_x
,
found_x
]
=
ast
->
m_symbol_table
->
find
(
"x"
,
position
);
REQUIRE
(
found_x
);
REQUIRE
(
not
symbol_x
->
attributes
().
isInitialized
());
auto
[
symbol_y
,
found_y
]
=
ast
->
m_symbol_table
->
find
(
"y"
,
position
);
REQUIRE
(
found_y
);
REQUIRE
(
symbol_y
->
attributes
().
isInitialized
());
}
SECTION
(
"Affectation"
)
{
std
::
string_view
data
=
R"(
R*R (x,y);
(x,y) = (2.3, 4.1);
)"
;
string_input
input
{
data
,
"test.pgs"
};
auto
ast
=
ASTBuilder
::
build
(
input
);
ASTSymbolTableBuilder
{
*
ast
};
ASTSymbolInitializationChecker
{
*
ast
};
position
position
{
internal
::
iterator
{
"fixture"
},
"fixture"
};
position
.
byte
=
data
.
size
();
// ensure that variables are declared at this point
auto
[
symbol_x
,
found_x
]
=
ast
->
m_symbol_table
->
find
(
"x"
,
position
);
REQUIRE
(
found_x
);
REQUIRE
(
symbol_x
->
attributes
().
isInitialized
());
auto
[
symbol_y
,
found_y
]
=
ast
->
m_symbol_table
->
find
(
"y"
,
position
);
REQUIRE
(
found_y
);
REQUIRE
(
symbol_y
->
attributes
().
isInitialized
());
}
}
SECTION
(
"errors"
)
{
SECTION
(
"used uninitialized"
)
...
...
@@ -102,7 +179,23 @@ N m = n;
auto
ast
=
ASTBuilder
::
build
(
input
);
ASTSymbolTableBuilder
{
*
ast
};
REQUIRE_THROWS_AS
(
ASTSymbolInitializationChecker
{
*
ast
},
parse_error
);
REQUIRE_THROWS_WITH
(
ASTSymbolInitializationChecker
{
*
ast
},
std
::
string
{
"uninitialized symbol 'n'"
});
}
SECTION
(
"used uninitialized in list affectation"
)
{
std
::
string_view
data
=
R"(
N k;
N*R (l, x);
(k, x) = (l, 3.2);
)"
;
string_input
input
{
data
,
"test.pgs"
};
auto
ast
=
ASTBuilder
::
build
(
input
);
ASTSymbolTableBuilder
{
*
ast
};
REQUIRE_THROWS_WITH
(
ASTSymbolInitializationChecker
{
*
ast
},
std
::
string
{
"uninitialized symbol 'l'"
});
}
SECTION
(
"used uninitialized in function"
)
...
...
@@ -116,7 +209,7 @@ let f : R->R, x->x+y;
auto
ast
=
ASTBuilder
::
build
(
input
);
ASTSymbolTableBuilder
{
*
ast
};
REQUIRE_THROWS_
AS
(
ASTSymbolInitializationChecker
{
*
ast
},
parse_error
);
REQUIRE_THROWS_
WITH
(
ASTSymbolInitializationChecker
{
*
ast
},
std
::
string
{
"uninitialized symbol 'y'"
}
);
}
}
}
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
register
or
sign in
to comment