File: type-test.h

package info (click to toggle)
binaryen 108-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 35,424 kB
  • sloc: cpp: 151,487; javascript: 62,522; ansic: 13,124; python: 5,260; pascal: 441; sh: 75; asm: 27; makefile: 8
file content (40 lines) | stat: -rw-r--r-- 1,242 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "wasm-type.h"
#include "gtest/gtest.h"

#ifndef wasm_test_gtest_type_test_h
#define wasm_test_gtest_type_test_h

// Helper test fixture for managing the global type system state.
template<wasm::TypeSystem system>
class TypeSystemTest : public ::testing::Test {
  wasm::TypeSystem originalSystem;

protected:
  void SetUp() override {
    originalSystem = wasm::getTypeSystem();
    wasm::setTypeSystem(system);
  }
  void TearDown() override {
    wasm::destroyAllTypesForTestingPurposesOnly();
    wasm::setTypeSystem(originalSystem);
  }

  // Utilities
  wasm::Struct makeStruct(wasm::TypeBuilder& builder,
                          std::initializer_list<size_t> indices) {
    using namespace wasm;
    FieldList fields;
    for (auto index : indices) {
      Type ref = builder.getTempRefType(builder[index], Nullable);
      fields.emplace_back(ref, Mutable);
    }
    return Struct(std::move(fields));
  }
};

using TypeTest = TypeSystemTest<wasm::TypeSystem::Isorecursive>;
using EquirecursiveTest = TypeSystemTest<wasm::TypeSystem::Equirecursive>;
using NominalTest = TypeSystemTest<wasm::TypeSystem::Nominal>;
using IsorecursiveTest = TypeSystemTest<wasm::TypeSystem::Isorecursive>;

#endif // wasm_test_gtest_type_test_h