mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 19:20:00 +00:00
[TS/JS] Move TS tests to dedicated folder and deps upgrade (#7508)
* Move TS tests to dedicated folder and deps upgrade * Attempt to fix generate_code * Fix dir on CI * Add js extension * Fix missing extension * Harmonize with test gen * Unexplained code gen change * Restore yarn.lock * Naive attempt to fix bazel stuff * Pin @bazel/typescript to 5.2.0 * Attempt to fix bazel * More tweak * Upgrade deps * Tweak? * Fix path * Fix test package Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
49
tests/ts/union_vector/character.ts
Normal file
49
tests/ts/union_vector/character.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import { Attacker, AttackerT } from './attacker.js';
|
||||
import { BookReader, BookReaderT } from './book-reader.js';
|
||||
import { Rapunzel, RapunzelT } from './rapunzel.js';
|
||||
|
||||
|
||||
export enum Character {
|
||||
NONE = 0,
|
||||
MuLan = 1,
|
||||
Rapunzel = 2,
|
||||
Belle = 3,
|
||||
BookFan = 4,
|
||||
Other = 5,
|
||||
Unused = 6
|
||||
}
|
||||
|
||||
export function unionToCharacter(
|
||||
type: Character,
|
||||
accessor: (obj:Attacker|BookReader|Rapunzel|string) => Attacker|BookReader|Rapunzel|string|null
|
||||
): Attacker|BookReader|Rapunzel|string|null {
|
||||
switch(Character[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'MuLan': return accessor(new Attacker())! as Attacker;
|
||||
case 'Rapunzel': return accessor(new Rapunzel())! as Rapunzel;
|
||||
case 'Belle': return accessor(new BookReader())! as BookReader;
|
||||
case 'BookFan': return accessor(new BookReader())! as BookReader;
|
||||
case 'Other': return accessor('') as string;
|
||||
case 'Unused': return accessor('') as string;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function unionListToCharacter(
|
||||
type: Character,
|
||||
accessor: (index: number, obj:Attacker|BookReader|Rapunzel|string) => Attacker|BookReader|Rapunzel|string|null,
|
||||
index: number
|
||||
): Attacker|BookReader|Rapunzel|string|null {
|
||||
switch(Character[type]) {
|
||||
case 'NONE': return null;
|
||||
case 'MuLan': return accessor(index, new Attacker())! as Attacker;
|
||||
case 'Rapunzel': return accessor(index, new Rapunzel())! as Rapunzel;
|
||||
case 'Belle': return accessor(index, new BookReader())! as BookReader;
|
||||
case 'BookFan': return accessor(index, new BookReader())! as BookReader;
|
||||
case 'Other': return accessor(index, '') as string;
|
||||
case 'Unused': return accessor(index, '') as string;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user