diff --git a/formats/valid_fail_regex.ksy b/formats/valid_fail_regex.ksy new file mode 100644 index 000000000..8fad5eee8 --- /dev/null +++ b/formats/valid_fail_regex.ksy @@ -0,0 +1,10 @@ +meta: + id: valid_fail_regex +seq: + - id: foo1 + type: str + encoding: ASCII + size: 6 + valid: + regex: P[a-z]{2}K-\d +#expecting lower case, where there are upper case letters in the file diff --git a/formats/valid_regex.ksy b/formats/valid_regex.ksy new file mode 100644 index 000000000..da5282d83 --- /dev/null +++ b/formats/valid_regex.ksy @@ -0,0 +1,17 @@ +meta: + id: valid_regex +seq: + - id: foo1 + type: str + encoding: ASCII + size: 6 + valid: + regex: P[A-Z]{2}K-\d + - id: pad1 + size: 2 + - id: foo2 + type: str + encoding: ASCII + size: 10 + valid: + regex: "[A-Z]{4}p*-+U-+DEF" diff --git a/spec/cpp_stl_11/test_valid_fail_regex.cpp b/spec/cpp_stl_11/test_valid_fail_regex.cpp new file mode 100644 index 000000000..08c13e162 --- /dev/null +++ b/spec/cpp_stl_11/test_valid_fail_regex.cpp @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#include +#include "valid_fail_regex.h" +#include +#include +#include +#include "kaitai/exceptions.h" + +BOOST_AUTO_TEST_CASE(test_valid_fail_regex) { + std::ifstream ifs("src/fixed_struct.bin", std::ifstream::binary); + kaitai::kstream ks(&ifs); + valid_fail_regex_t* r = nullptr; + BOOST_CHECK_THROW( + r = new valid_fail_regex_t(&ks), + kaitai::validation_regex_match_error + ); + + delete r; +} diff --git a/spec/cpp_stl_11/test_valid_regex.cpp b/spec/cpp_stl_11/test_valid_regex.cpp new file mode 100644 index 000000000..3b827436c --- /dev/null +++ b/spec/cpp_stl_11/test_valid_regex.cpp @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#include +#include "valid_regex.h" +#include +#include +#include + +BOOST_AUTO_TEST_CASE(test_valid_regex) { + std::ifstream ifs("src/fixed_struct.bin", std::ifstream::binary); + kaitai::kstream ks(&ifs); + valid_regex_t* r = new valid_regex_t(&ks); + + + delete r; +} diff --git a/spec/cpp_stl_98/test_valid_fail_regex.cpp b/spec/cpp_stl_98/test_valid_fail_regex.cpp new file mode 100644 index 000000000..54dfd5b19 --- /dev/null +++ b/spec/cpp_stl_98/test_valid_fail_regex.cpp @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#include +#include "valid_fail_regex.h" +#include +#include +#include +#include "kaitai/exceptions.h" + +BOOST_AUTO_TEST_CASE(test_valid_fail_regex) { + std::ifstream ifs("src/fixed_struct.bin", std::ifstream::binary); + kaitai::kstream ks(&ifs); + valid_fail_regex_t* r = 0; + BOOST_CHECK_THROW( + r = new valid_fail_regex_t(&ks), + kaitai::validation_regex_match_error + ); + + delete r; +} diff --git a/spec/go/valid_regex_test.go b/spec/go/valid_regex_test.go new file mode 100644 index 000000000..3a42232ee --- /dev/null +++ b/spec/go/valid_regex_test.go @@ -0,0 +1,31 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +package spec + +import ( + "runtime/debug" + "os" + "testing" + "github.com/kaitai-io/kaitai_struct_go_runtime/kaitai" + . "test_formats" +) + +func TestValidRegex(t *testing.T) { + defer func() { + if r := recover(); r != nil { + debug.PrintStack() + t.Fatal("unexpected panic:", r) + } + }() + f, err := os.Open("../../src/fixed_struct.bin") + if err != nil { + t.Fatal(err) + } + s := kaitai.NewStream(f) + var r ValidRegex + err = r.Read(s, &r, &r) + if err != nil { + t.Fatal(err) + } + +} diff --git a/spec/java/src/io/kaitai/struct/spec/TestValidFailRegex.java b/spec/java/src/io/kaitai/struct/spec/TestValidFailRegex.java new file mode 100644 index 000000000..41f0ab2d2 --- /dev/null +++ b/spec/java/src/io/kaitai/struct/spec/TestValidFailRegex.java @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +package io.kaitai.struct.spec; + +import io.kaitai.struct.testformats.ValidFailRegex; +import org.testng.annotations.Test; +import static org.testng.Assert.*; +import io.kaitai.struct.KaitaiStream; +public class TestValidFailRegex extends CommonSpec { + + @Test(expectedExceptions = KaitaiStream.ValidationRegexMatchError.class) + public void testValidFailRegex() throws Exception { + ValidFailRegex r = ValidFailRegex.fromFile(SRC_DIR + "fixed_struct.bin"); + } +} diff --git a/spec/java/src/io/kaitai/struct/spec/TestValidRegex.java b/spec/java/src/io/kaitai/struct/spec/TestValidRegex.java new file mode 100644 index 000000000..d43f8ad23 --- /dev/null +++ b/spec/java/src/io/kaitai/struct/spec/TestValidRegex.java @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +package io.kaitai.struct.spec; + +import io.kaitai.struct.testformats.ValidRegex; +import org.testng.annotations.Test; +import static org.testng.Assert.*; +public class TestValidRegex extends CommonSpec { + + @Test + public void testValidRegex() throws Exception { + ValidRegex r = ValidRegex.fromFile(SRC_DIR + "fixed_struct.bin"); + + } +} diff --git a/spec/javascript/test_valid_regex.js b/spec/javascript/test_valid_regex.js new file mode 100644 index 000000000..60df42340 --- /dev/null +++ b/spec/javascript/test_valid_regex.js @@ -0,0 +1,8 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +var assert = require('assert'); +var testHelper = require('testHelper'); + +testHelper('ValidRegex', 'src/fixed_struct.bin', function(r, ValidRegex) { + +}); diff --git a/spec/ks/valid_fail_regex.kst b/spec/ks/valid_fail_regex.kst new file mode 100644 index 000000000..9fae3f00a --- /dev/null +++ b/spec/ks/valid_fail_regex.kst @@ -0,0 +1,3 @@ +id: valid_fail_regex +data: fixed_struct.bin +exception: ValidationRegexMatchError diff --git a/spec/ks/valid_regex.kst b/spec/ks/valid_regex.kst new file mode 100644 index 000000000..1945a7eff --- /dev/null +++ b/spec/ks/valid_regex.kst @@ -0,0 +1,2 @@ +id: valid_regex +data: fixed_struct.bin diff --git a/spec/python/test_valid_fail_regex.py b/spec/python/test_valid_fail_regex.py new file mode 100644 index 000000000..761a09b93 --- /dev/null +++ b/spec/python/test_valid_fail_regex.py @@ -0,0 +1,12 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +import unittest +import kaitaistruct + +from valid_fail_regex import ValidFailRegex + +class TestValidFailRegex(unittest.TestCase): + def test_valid_fail_regex(self): + with self.assertRaises(kaitaistruct.ValidationRegexMatchError): + with ValidFailRegex.from_file('src/fixed_struct.bin') as r: + pass diff --git a/spec/python/test_valid_regex.py b/spec/python/test_valid_regex.py new file mode 100644 index 000000000..13950ef21 --- /dev/null +++ b/spec/python/test_valid_regex.py @@ -0,0 +1,11 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +import unittest + +from valid_regex import ValidRegex + +class TestValidRegex(unittest.TestCase): + def test_valid_regex(self): + with ValidRegex.from_file('src/fixed_struct.bin') as r: + + pass