Skip to content

Commit

Permalink
added an option with records to the quint model and the parse test
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-gavran committed Dec 20, 2023
1 parent 7a2c2c6 commit 0090cb1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
21 changes: 18 additions & 3 deletions tests/fixtures/SumTypes.qnt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module SumTypes {

type Option =
| Some(int)
type Option =
| None
| Some(int)
| SomeMore({x: int, y: bool})

var value: Option

Expand All @@ -14,13 +15,27 @@ module SumTypes {
value' = Some(x)
}

action addComponent(y: bool) : bool = all {
match value {
| Some(x) => value' = SomeMore({x: x, y: y})
| SomeMore(r) => value' = SomeMore({x: r.x, y: y})
| None => value' = None
}
}

action incrValue = all {
match value {
| Some(x) => value' = Some(x + 1)
| None => value' = None
| SomeMore(r) => value' = SomeMore({x: r.x + 1, y: r.y})
}
}

run exampleTest = init.then(setValue(40)).then(incrValue).then(incrValue)
run exampleTest =
init
.then(setValue(40))
.then(incrValue)
.then(addComponent(true))
.then(incrValue)

}
2 changes: 1 addition & 1 deletion tests/fixtures/SumTypes0.itf.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"#meta":{"format":"ITF","format-description":"https://apalache.informal.systems/docs/adr/015adr-trace.html","source":"SumTypes.qnt","status":"passed","description":"Created by Quint on Thu Dec 07 2023 11:21:01 GMT+0100 (GMT+01:00)","timestamp":1701944461444},"vars":["value"],"states":[{"#meta":{"index":0},"value":{"tag":"None","value":{}}},{"#meta":{"index":1},"value":{"tag":"Some","value":{"#bigint":"40"}}},{"#meta":{"index":2},"value":{"tag":"Some","value":{"#bigint":"41"}}}]}
{"#meta":{"format":"ITF","format-description":"https://apalache.informal.systems/docs/adr/015adr-trace.html","source":"SumTypes.qnt","status":"passed","description":"Created by Quint on Wed Dec 20 2023 10:52:13 GMT+0100 (Central European Standard Time)","timestamp":1703065933486},"vars":["value"],"states":[{"#meta":{"index":0},"value":{"tag":"None","value":{}}},{"#meta":{"index":1},"value":{"tag":"Some","value":{"#bigint":"40"}}},{"#meta":{"index":2},"value":{"tag":"Some","value":{"#bigint":"41"}}},{"#meta":{"index":3},"value":{"tag":"SomeMore","value":{"x":{"#bigint":"41"},"y":true}}}]}
14 changes: 14 additions & 0 deletions tests/sum_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ use serde_json::json;

use itf::de::{As, Integer, Same};

#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
pub struct SomeMoreArgs {
pub x: BigInt,
pub y: bool,
}

#[derive(Debug, PartialEq, Eq, Deserialize)]
#[serde(tag = "tag", content = "value")]
enum IntOption {
Some(BigInt),
SomeMore(SomeMoreArgs),
None,
}

Expand All @@ -25,6 +32,13 @@ fn parse_trace() {
assert_eq!(trace.states[0].value.value, IntOption::None);
assert_eq!(trace.states[1].value.value, IntOption::Some(40.into()));
assert_eq!(trace.states[2].value.value, IntOption::Some(41.into()));
assert_eq!(
trace.states[3].value.value,
IntOption::SomeMore(SomeMoreArgs {
x: 41.into(),
y: true,
})
);
}

#[test]
Expand Down

0 comments on commit 0090cb1

Please sign in to comment.