Skip to content

Commit

Permalink
Add failing test for #1231.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Jul 7, 2022
1 parent 982e492 commit 80e9dbd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/Baseline/spicy.types.unit.synchronize-on-gap/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[spicy-verbose] - state: type=sync::Xs input="A<gap>..." stream=0xXXXXXXXX offsets=0/0/1027 chunks=3 frozen=no mode=default trim=yes lah=n/a lah_token="n/a" recovering=no
[spicy-verbose] - parsing production: Unit: sync_Xs -> xs
[spicy] sync::Xs
[spicy-verbose] - state: type=sync::Xs input="A<gap>..." stream=0xXXXXXXXX offsets=0/0/1027 chunks=3 frozen=no mode=default trim=no lah=n/a lah_token="n/a" recovering=no
[spicy-verbose] - parsing production: While: xs -> while(<look-ahead-found>): anon
[spicy-verbose] - state: type=sync::Xs input="A<gap>..." stream=0xXXXXXXXX offsets=0/0/1027 chunks=3 frozen=no mode=default trim=no lah=1 lah_token="A" recovering=no
[spicy-verbose] - state: type=sync::Xs input="A<gap>..." stream=0xXXXXXXXX offsets=0/0/1027 chunks=3 frozen=no mode=default trim=no lah=1 lah_token="A" recovering=no
[spicy-verbose] - parsing production: Ctor: anon -> /(A|B|C)/ (regexp) (container 'xs')
[spicy-verbose] - consuming look-ahead token
[spicy-verbose] - got container item
[spicy] failed to parse list element, will try to synchronize at next possible element
[spicy-verbose] - state: type=sync::Xs input="<gap>..." stream=0xXXXXXXXX offsets=0/1/1027 chunks=3 frozen=no mode=default trim=no lah=n/a lah_token="n/a" recovering=yes
[spicy-verbose] - state: type=sync::Xs input="C" stream=0xXXXXXXXX offsets=0/1026/1027 chunks=3 frozen=no mode=default trim=no lah=1 lah_token="C" recovering=yes
[spicy-verbose] - state: type=sync::Xs input="C" stream=0xXXXXXXXX offsets=0/1026/1027 chunks=3 frozen=no mode=default trim=no lah=1 lah_token="C" recovering=no
[spicy-verbose] - parsing production: Ctor: anon -> /(A|B|C)/ (regexp) (container 'xs')
[spicy-verbose] - consuming look-ahead token
[spicy-verbose] - got container item
[spicy-verbose] suspending to wait for more input for stream 0xXXXXXXXX, currently have 0
[$xs=[b"A", b"C"]]
39 changes: 39 additions & 0 deletions tests/spicy/types/unit/synchronize-on-gap.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# @TEST-DOC: Validates that if a gap is encountered during recovery we can still resynchronize.
#
# @TEST-EXEC: spicyc -cdo sync.cc sync.spicy
# @TEST-EXEC: spicyc -ldo sync-linker.cc sync.spicy
# @TEST-EXEC: spicyc -Pdo sync.h sync.spicy
# @TEST-EXEC: $(spicy-config --cxx-launcher --cxx) -o main main.cc sync.cc sync-linker.cc $(spicy-config --debug --cxxflags --ldflags)
# @TEST-EXEC: HILTI_DEBUG=spicy:spicy-verbose ./main >output 2>&1
# @TEST-EXEC: TEST_DIFF_CANONIFIER=${SCRIPTS}/canonify-spicy-debug btest-diff output

# @TEST-START-FILE sync.spicy
module sync;

public type Xs = unit {
xs: (/(A|B|C)/ &synchronize)[];
on %synced { confirm; }
};
# @TEST-END-FILE

# @TEST-START-FILE main.cc
#include <hilti/rt/libhilti.h>

#include "sync.h"

int main() {
hilti::rt::init();

auto xs = hilti::rt::reference::make_value<__hlt::sync::Xs>();

hilti::rt::ValueReference<hilti::rt::Stream> stream;
stream->append("A");
stream->append(nullptr, 1024); // Gap.
stream->append("BC");

hlt::sync::Xs::parse2(xs, stream, {}, {});
std::cout << xs << '\n';

hilti::rt::done();
}
# @TEST-END-FILE

0 comments on commit 80e9dbd

Please sign in to comment.