-
Notifications
You must be signed in to change notification settings - Fork 12
Add tests for case expressions #179
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
Merged
NlightNFotis
merged 6 commits into
diffblue:master
from
NlightNFotis:fix_case_statement_expressions
Apr 1, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9650d05
Add basic test for case expressions
NlightNFotis 8c3fb05
Add a test for case expression where the others case
NlightNFotis 585f987
Add failing test case for case expressions with
NlightNFotis 036cc5f
Fix case expression with or in condition crashing CBMC
NlightNFotis ec1e673
Add test for case expression where a condition is a range
NlightNFotis 46a707c
Convert commits to use functions that return values
NlightNFotis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
testsuite/gnat2goto/tests/case_expression/case_expression.adb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
procedure Case_Expression is | ||
type Weekday is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); | ||
Day : Weekday := Tue; | ||
Hours : Integer; | ||
-- We need this to avoid the front-end's | ||
-- constant folding mess up with the validity | ||
-- of this test. | ||
function Nested_Case_Expr (WDay : Weekday) | ||
return Integer is | ||
begin | ||
return (case WDay is | ||
when Mon => 1, | ||
when Tue => 2, | ||
when Wed => 3, | ||
when Thu => 4, | ||
when Fri => 5, | ||
when Sat => 6, | ||
when Sun => 7); | ||
end Nested_Case_Expr; | ||
begin | ||
Hours := Nested_Case_Expr (Day); | ||
pragma Assert (Hours = 2); | ||
pragma Assert (Hours /= 1); | ||
end Case_Expression; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[1] file case_expression.adb line 22 assertion: SUCCESS | ||
[2] file case_expression.adb line 23 assertion: SUCCESS | ||
VERIFICATION SUCCESSFUL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from test_support import * | ||
|
||
prove() |
20 changes: 20 additions & 0 deletions
20
testsuite/gnat2goto/tests/case_expression_others/case_expression_others.adb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
procedure Case_Expression_Others is | ||
Invalid_Ternary : Integer := 3; | ||
Valid_Result : Integer; | ||
-- We need this to make sure that the | ||
-- frontend's constant folding isn't | ||
-- causing us to test something other | ||
-- than what we originally expected. | ||
function Nested_One (Ternary : Integer) return Integer is | ||
begin | ||
return (case Invalid_Ternary is | ||
when 0 => 0, | ||
when 1 => 0, | ||
when 2 => 0, | ||
when others => 1); | ||
end Nested_One; | ||
begin | ||
Valid_Result := Nested_One (Invalid_Ternary); | ||
pragma Assert (Valid_Result = 1); | ||
pragma Assert (Valid_Result /= 0); | ||
end Case_Expression_Others; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[1] file case_expression_others.adb line 18 assertion: SUCCESS | ||
[2] file case_expression_others.adb line 19 assertion: SUCCESS | ||
VERIFICATION SUCCESSFUL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from test_support import * | ||
|
||
prove() |
12 changes: 12 additions & 0 deletions
12
testsuite/gnat2goto/tests/case_expression_range/case_expression_range.adb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
procedure Case_Expression_Range is | ||
Random_Val : Integer := 10; | ||
Result : Integer; | ||
begin | ||
Result := (case Random_Val is | ||
when 1..10 => 1, | ||
when 11..20 => 2, | ||
when others => 3); | ||
|
||
pragma Assert (Result = 1); | ||
pragma Assert (Result /= 3); | ||
end Case_Expression_Range; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALL XFAIL gnat2goto throws exceptions but produces something that crashes CBMC even harder |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from test_support import * | ||
|
||
prove() |
13 changes: 13 additions & 0 deletions
13
testsuite/gnat2goto/tests/case_expression_vals/case_expression_or.adb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
procedure Case_Expression_Or is | ||
type Weekday is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); | ||
Day : Weekday := Tue; | ||
Hours : Integer; | ||
begin | ||
Hours := (case Day is | ||
when Mon | Tue => 1, | ||
when Wed | Thu => 2, | ||
when Fri | Sat => 3, | ||
when Sun => 0); | ||
pragma Assert (Hours = 1); | ||
pragma Assert (Hours /= 2); | ||
end Case_Expression_Or; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[1] file case_expression_or.adb line 11 assertion: SUCCESS | ||
[2] file case_expression_or.adb line 12 assertion: SUCCESS | ||
VERIFICATION SUCCESSFUL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from test_support import * | ||
|
||
prove() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect handling a range expression should be fairly easy - a literal range should always be translatable like this
x in a..b ===> a <= x and x <= b
I'd think