Skip to content

Commit fff2200

Browse files
committed
Regen KST expr_bits
1 parent ba26622 commit fff2200

File tree

13 files changed

+337
-0
lines changed

13 files changed

+337
-0
lines changed

spec/construct/test_expr_bits.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
import unittest
4+
5+
from expr_bits import _schema
6+
7+
class TestExprBits(unittest.TestCase):
8+
def test_expr_bits(self):
9+
r = _schema.parse_file('src/switch_opcodes.bin')
10+
11+
self.assertEqual(r.a, 2)
12+
self.assertEqual(r.enum_seq, self._root.Items.foo)
13+
self.assertEqual(r.byte_size, b"\x66\x6F")
14+
self.assertEqual(len(r.repeat_expr), 2)
15+
self.assertEqual(r.repeat_expr[0], 111)
16+
self.assertEqual(r.repeat_expr[1], 98)
17+
self.assertEqual(r.switch_on_type, 97)
18+
self.assertEqual(r.switch_on_endian.foo, 29184)
19+
self.assertEqual(r.enum_inst, self._root.Items.bar)
20+
self.assertEqual(r.inst_pos, 111)

spec/cpp_stl_11/test_expr_bits.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
#include <boost/test/unit_test.hpp>
4+
#include "expr_bits.h"
5+
#include <iostream>
6+
#include <fstream>
7+
#include <vector>
8+
9+
10+
BOOST_AUTO_TEST_CASE(test_expr_bits) {
11+
std::ifstream ifs("src/switch_opcodes.bin", std::ifstream::binary);
12+
kaitai::kstream ks(&ifs);
13+
expr_bits_t* r = new expr_bits_t(&ks);
14+
15+
16+
BOOST_CHECK_EQUAL(r->a(), 2);
17+
BOOST_CHECK_EQUAL(r->enum_seq(), expr_bits_t::ITEMS_FOO);
18+
BOOST_CHECK_EQUAL(r->byte_size(), std::string("\x66\x6F", 2));
19+
BOOST_CHECK_EQUAL(r->repeat_expr()->size(), 2);
20+
BOOST_CHECK_EQUAL(r->repeat_expr()->at(0), 111);
21+
BOOST_CHECK_EQUAL(r->repeat_expr()->at(1), 98);
22+
BOOST_CHECK_EQUAL(r->switch_on_type(), 97);
23+
BOOST_CHECK_EQUAL(r->switch_on_endian()->foo(), 29184);
24+
BOOST_CHECK_EQUAL(r->enum_inst(), expr_bits_t::ITEMS_BAR);
25+
BOOST_CHECK_EQUAL(r->inst_pos(), 111);
26+
27+
delete r;
28+
}

spec/cpp_stl_98/test_expr_bits.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
#include <boost/test/unit_test.hpp>
4+
#include "expr_bits.h"
5+
#include <iostream>
6+
#include <fstream>
7+
#include <vector>
8+
9+
10+
BOOST_AUTO_TEST_CASE(test_expr_bits) {
11+
std::ifstream ifs("src/switch_opcodes.bin", std::ifstream::binary);
12+
kaitai::kstream ks(&ifs);
13+
expr_bits_t* r = new expr_bits_t(&ks);
14+
15+
16+
BOOST_CHECK_EQUAL(r->a(), 2);
17+
BOOST_CHECK_EQUAL(r->enum_seq(), expr_bits_t::ITEMS_FOO);
18+
BOOST_CHECK_EQUAL(r->byte_size(), std::string("\x66\x6F", 2));
19+
BOOST_CHECK_EQUAL(r->repeat_expr()->size(), 2);
20+
BOOST_CHECK_EQUAL(r->repeat_expr()->at(0), 111);
21+
BOOST_CHECK_EQUAL(r->repeat_expr()->at(1), 98);
22+
BOOST_CHECK_EQUAL(r->switch_on_type(), 97);
23+
BOOST_CHECK_EQUAL(r->switch_on_endian()->foo(), 29184);
24+
BOOST_CHECK_EQUAL(r->enum_inst(), expr_bits_t::ITEMS_BAR);
25+
BOOST_CHECK_EQUAL(r->inst_pos(), 111);
26+
27+
delete r;
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
using NUnit.Framework;
4+
5+
namespace Kaitai
6+
{
7+
[TestFixture]
8+
public class SpecExprBits : CommonSpec
9+
{
10+
[Test]
11+
public void TestExprBits()
12+
{
13+
var r = ExprBits.FromFile(SourceFile("switch_opcodes.bin"));
14+
15+
16+
Assert.AreEqual(r.A, 2);
17+
Assert.AreEqual(r.EnumSeq, ExprBits.Items.Foo);
18+
Assert.AreEqual(r.ByteSize, new byte[] { 102, 111 });
19+
Assert.AreEqual(r.RepeatExpr.Count, 2);
20+
Assert.AreEqual(r.RepeatExpr[0], 111);
21+
Assert.AreEqual(r.RepeatExpr[1], 98);
22+
Assert.AreEqual(r.SwitchOnType, 97);
23+
Assert.AreEqual(r.SwitchOnEndian.Foo, 29184);
24+
Assert.AreEqual(r.EnumInst, ExprBits.Items.Bar);
25+
Assert.AreEqual(r.InstPos, 111);
26+
}
27+
}
28+
}

spec/go/expr_bits_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
package spec
4+
5+
import (
6+
"runtime/debug"
7+
"os"
8+
"testing"
9+
"github.com/kaitai-io/kaitai_struct_go_runtime/kaitai"
10+
. "test_formats"
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestExprBits(t *testing.T) {
15+
defer func() {
16+
if r := recover(); r != nil {
17+
debug.PrintStack()
18+
t.Fatal("unexpected panic:", r)
19+
}
20+
}()
21+
f, err := os.Open("../../src/switch_opcodes.bin")
22+
if err != nil {
23+
t.Fatal(err)
24+
}
25+
s := kaitai.NewStream(f)
26+
var r ExprBits
27+
err = r.Read(s, &r, &r)
28+
if err != nil {
29+
t.Fatal(err)
30+
}
31+
32+
assert.EqualValues(t, 2, r.A)
33+
assert.EqualValues(t, ExprBits_Items__Foo, r.EnumSeq)
34+
assert.EqualValues(t, []uint8{102, 111}, r.ByteSize)
35+
assert.EqualValues(t, 2, len(r.RepeatExpr))
36+
assert.EqualValues(t, 111, r.RepeatExpr[0])
37+
assert.EqualValues(t, 98, r.RepeatExpr[1])
38+
assert.EqualValues(t, 97, r.SwitchOnType)
39+
assert.EqualValues(t, 29184, r.SwitchOnEndian.Foo)
40+
tmp1, err := r.EnumInst()
41+
if err != nil {
42+
t.Fatal(err)
43+
}
44+
assert.EqualValues(t, ExprBits_Items__Bar, tmp1)
45+
tmp2, err := r.InstPos()
46+
if err != nil {
47+
t.Fatal(err)
48+
}
49+
assert.EqualValues(t, 111, tmp2)
50+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
package io.kaitai.struct.spec;
4+
5+
import io.kaitai.struct.testformats.ExprBits;
6+
import org.testng.annotations.Test;
7+
import static org.testng.Assert.*;
8+
public class TestExprBits extends CommonSpec {
9+
10+
@Test
11+
public void testExprBits() throws Exception {
12+
ExprBits r = ExprBits.fromFile(SRC_DIR + "switch_opcodes.bin");
13+
14+
assertIntEquals(r.a(), 2);
15+
assertEquals(r.enumSeq(), ExprBits.Items.FOO);
16+
assertEquals(r.byteSize(), new byte[] { 102, 111 });
17+
assertIntEquals(r.repeatExpr().size(), 2);
18+
assertIntEquals(r.repeatExpr().get((int) 0), 111);
19+
assertIntEquals(r.repeatExpr().get((int) 1), 98);
20+
assertIntEquals(r.switchOnType(), 97);
21+
assertIntEquals(r.switchOnEndian().foo(), 29184);
22+
assertEquals(r.enumInst(), ExprBits.Items.BAR);
23+
assertIntEquals(r.instPos(), 111);
24+
}
25+
}

spec/javascript/test_expr_bits.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
var assert = require('assert');
4+
var testHelper = require('testHelper');
5+
var hexString = require('hexString');
6+
7+
testHelper('ExprBits', 'src/switch_opcodes.bin', function(r, ExprBits) {
8+
9+
assert.strictEqual(r.a, 2);
10+
assert.strictEqual(r.enumSeq, ExprBits.Items.FOO);
11+
assert.strictEqual(hexString(r.byteSize), hexString([102, 111]));
12+
assert.strictEqual(r.repeatExpr.length, 2);
13+
assert.strictEqual(r.repeatExpr[0], 111);
14+
assert.strictEqual(r.repeatExpr[1], 98);
15+
assert.strictEqual(r.switchOnType, 97);
16+
assert.strictEqual(r.switchOnEndian.foo, 29184);
17+
assert.strictEqual(r.enumInst, ExprBits.Items.BAR);
18+
assert.strictEqual(r.instPos, 111);
19+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
import unittest, os, streams, options, sequtils, ../testhelpers
4+
import ../../../compiled/nim/expr_bits
5+
6+
var
7+
stream = newFileStream("test_out/nim/junitreports/expr_bits.xml", fmWrite)
8+
outputFormatter = newJUnitOutputFormatter(stream)
9+
addOutputFormatter(outputFormatter)
10+
11+
suite "Kaitai Struct Compiler Test Suite":
12+
test "Nim: ExprBits":
13+
let r = ExprBits.fromFile("src/switch_opcodes.bin")
14+
15+
check(r.a == uint64(2))
16+
check(r.enumSeq == Items())
17+
check(r.byteSize == seq[byte](@[102, 111].mapIt(toByte(it))))
18+
check(len(r.repeatExpr) == int(2))
19+
check(r.repeatExpr[0] == int8(111))
20+
check(r.repeatExpr[1] == int8(98))
21+
check(r.switchOnType == int8(97))
22+
check(r.switchOnEndian.foo == int16(29184))
23+
check(r.enumInst == Items())
24+
check(r.instPos == int8(111))
25+
26+
close(outputFormatter)

spec/perl/TestExprBits.t

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
package spec::perl::TestExprBits;
4+
5+
use strict;
6+
use warnings;
7+
use base qw(Test::Class);
8+
use Test::More;
9+
use ExprBits;
10+
11+
sub test_expr_bits: Test(10) {
12+
my $r = ExprBits->from_file('src/switch_opcodes.bin');
13+
14+
15+
is($r->a(), 2, 'Equals');
16+
is($r->enum_seq(), $ExprBits::ITEMS_FOO, 'Equals');
17+
is($r->byte_size(), pack('C*', (102, 111)), 'Equals');
18+
is(scalar(@{$r->repeat_expr()}), 2, 'Equals');
19+
is(@{$r->repeat_expr()}[0], 111, 'Equals');
20+
is(@{$r->repeat_expr()}[1], 98, 'Equals');
21+
is($r->switch_on_type(), 97, 'Equals');
22+
is($r->switch_on_endian()->foo(), 29184, 'Equals');
23+
is($r->enum_inst(), $ExprBits::ITEMS_BAR, 'Equals');
24+
is($r->inst_pos(), 111, 'Equals');
25+
}
26+
27+
Test::Class->runtests;

spec/php/ExprBitsTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
// Autogenerated from KST: please remove this line if doing any edits by hand!
3+
4+
namespace Kaitai\Struct\Tests;
5+
6+
class ExprBitsTest extends TestCase {
7+
public function testExprBits() {
8+
$r = ExprBits::fromFile(self::SRC_DIR_PATH . '/switch_opcodes.bin');
9+
10+
11+
$this->assertEquals(2, $r->a());
12+
$this->assertEquals(\Kaitai\Struct\Tests\ExprBits\Items::FOO, $r->enumSeq());
13+
$this->assertEquals("\x66\x6F", $r->byteSize());
14+
$this->assertEquals(2, count($r->repeatExpr()));
15+
$this->assertEquals(111, $r->repeatExpr()[0]);
16+
$this->assertEquals(98, $r->repeatExpr()[1]);
17+
$this->assertEquals(97, $r->switchOnType());
18+
$this->assertEquals(29184, $r->switchOnEndian()->foo());
19+
$this->assertEquals(\Kaitai\Struct\Tests\ExprBits\Items::BAR, $r->enumInst());
20+
$this->assertEquals(111, $r->instPos());
21+
}
22+
}

spec/python/test_expr_bits.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
import unittest
4+
5+
from expr_bits import ExprBits
6+
7+
class TestExprBits(unittest.TestCase):
8+
def test_expr_bits(self):
9+
with ExprBits.from_file('src/switch_opcodes.bin') as r:
10+
11+
self.assertEqual(r.a, 2)
12+
self.assertEqual(r.enum_seq, ExprBits.Items.foo)
13+
self.assertEqual(r.byte_size, b"\x66\x6F")
14+
self.assertEqual(len(r.repeat_expr), 2)
15+
self.assertEqual(r.repeat_expr[0], 111)
16+
self.assertEqual(r.repeat_expr[1], 98)
17+
self.assertEqual(r.switch_on_type, 97)
18+
self.assertEqual(r.switch_on_endian.foo, 29184)
19+
self.assertEqual(r.enum_inst, ExprBits.Items.bar)
20+
self.assertEqual(r.inst_pos, 111)

spec/ruby/expr_bits_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
require 'expr_bits'
4+
5+
RSpec.describe ExprBits do
6+
it 'parses test properly' do
7+
r = ExprBits.from_file('src/switch_opcodes.bin')
8+
9+
expect(r.a).to eq 2
10+
expect(r.enum_seq).to eq :items_foo
11+
expect(r.byte_size).to eq [102, 111].pack('C*')
12+
expect(r.repeat_expr.length).to eq 2
13+
expect(r.repeat_expr[0]).to eq 111
14+
expect(r.repeat_expr[1]).to eq 98
15+
expect(r.switch_on_type).to eq 97
16+
expect(r.switch_on_endian.foo).to eq 29184
17+
expect(r.enum_inst).to eq :items_bar
18+
expect(r.inst_pos).to eq 111
19+
end
20+
end

spec/rust/test_expr_bits.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Autogenerated from KST: please remove this line if doing any edits by hand!
2+
3+
extern crate kaitai_struct;
4+
extern crate rust;
5+
6+
use kaitai_struct::KaitaiStruct;
7+
use rust::ExprBits;
8+
9+
#[test]
10+
fn test_expr_bits() {
11+
if let Ok(r) = ExprBits::from_file("src/switch_opcodes.bin") {
12+
13+
assert_eq!(r.a, 2);
14+
assert_eq!(r.enum_seq, ExprBits__Items::FOO);
15+
assert_eq!(r.byte_size, vec!([0x66, 0x6f]));
16+
assert_eq!(r.repeat_expr.len(), 2);
17+
assert_eq!(r.repeat_expr[0], 111);
18+
assert_eq!(r.repeat_expr[1], 98);
19+
assert_eq!(r.switch_on_type, 97);
20+
assert_eq!(r.switch_on_endian.foo, 29184);
21+
assert_eq!(r.enum_inst, ExprBits__Items::BAR);
22+
assert_eq!(r.inst_pos, 111);
23+
}
24+
}

0 commit comments

Comments
 (0)