Files
dolt/nomdl/codegen/test/struct-with-unions-test.js
Erik Arvidsson b79d89963f JS codegen: Add tests and make more things work (#1182)
Now the generated code is tested and most things work.



To generate a .noms.js file use the codegen go binary



Things that are not complete/needs improvements include:

- Recursive structs

- Structs with annonymous unions

- Enum -- constants for the values



Issue #1081
2016-04-07 14:11:40 -07:00

30 lines
809 B
JavaScript

// @flow
import {assert} from 'chai';
import {suite, test} from 'mocha';
import {
StructWithUnions,
__unionOfBOfFloat64AndCOfString,
__unionOfEOfFloat64AndFOfString,
} from './gen/struct_with_unions.noms.js';
suite('struct_optional.noms', () => {
test('constructor', async () => {
// TODO: This needs to be cleaner.
const swu = new StructWithUnions({
a: new __unionOfBOfFloat64AndCOfString({b: 1}),
d: new __unionOfEOfFloat64AndFOfString({f:'hi'}),
});
assert.equal(swu.a.b, 1);
assert.equal(swu.d.f, 'hi');
const swu2 = swu.setA(swu.a.setC('bye'));
const swu3 = new StructWithUnions({
a: new __unionOfBOfFloat64AndCOfString({c: 'bye'}),
d: new __unionOfEOfFloat64AndFOfString({f:'hi'}),
});
assert.isTrue(swu2.equals(swu3));
});
});