Skip to content

Commit

Permalink
refactor: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Nov 3, 2023
1 parent 4bc5980 commit b09f257
Show file tree
Hide file tree
Showing 230 changed files with 1,020 additions and 6,786 deletions.
2 changes: 1 addition & 1 deletion packages/beize_compiler/lib/compiler/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BeizeCompiler {
currentFunction = BeizeFunctionConstant(
isAsync: isAsync,
arguments: <int>[],
chunk: BeizeChunk.empty(moduleIndex),
chunk: BeizeChunk.empty(),
);
scopeDepth = 0;
loops = <BeizeCompilerLoopState>[];
Expand Down
3 changes: 2 additions & 1 deletion packages/beize_compiler/lib/disassembler/disassembler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ class BeizeDisassembler {
final BeizeFunctionConstant function =
program.constantAt(functionIndex) as BeizeFunctionConstant;
output.write(
'> $moduleName (constant [$nameIndex]) at constant [$functionIndex] ${nameIndex == 0 ? "(entrypoint)" : ""}');
'> $moduleName (constant [$nameIndex]) at constant [$functionIndex] ${nameIndex == 0 ? "(entrypoint)" : ""}',
);
final BeizeDisassembler disassembler =
BeizeDisassembler(program, function.chunk, output);
disassembler.dissassemble();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,6 @@ Future<void> main() async {
'addition_assignment_1.beize',
);

test('$title - Bytecode', () async {
final BeizeTestProgram expectedProgram = BeizeTestProgram();
final BeizeTestChunk expectedModule0 =
expectedProgram.addModule(0, 0, 'addition_assignment_1.beize');
expectedModule0.addOpCode(BeizeOpCodes.opConstant);
expectedModule0.addConstant(3, 1.0);
expectedModule0.addOpCode(BeizeOpCodes.opDeclare);
expectedModule0.addConstant(2, 'result');
expectedModule0.addOpCode(BeizeOpCodes.opPop);
expectedModule0.addOpCode(BeizeOpCodes.opLookup);
expectedModule0.addConstant(2, 'result');
expectedModule0.addOpCode(BeizeOpCodes.opConstant);
expectedModule0.addConstant(4, 2.0);
expectedModule0.addOpCode(BeizeOpCodes.opAdd);
expectedModule0.addOpCode(BeizeOpCodes.opAssign);
expectedModule0.addConstant(2, 'result');
expectedModule0.addOpCode(BeizeOpCodes.opPop);
expectedModule0.addOpCode(BeizeOpCodes.opLookup);
expectedModule0.addConstant(5, 'out');
expectedModule0.addOpCode(BeizeOpCodes.opConstant);
expectedModule0.addConstant(6, '');
expectedModule0.addOpCode(BeizeOpCodes.opLookup);
expectedModule0.addConstant(2, 'result');
expectedModule0.addOpCode(BeizeOpCodes.opAdd);
expectedModule0.addOpCode(BeizeOpCodes.opCall);
expectedModule0.addCode(1);
expectedModule0.addOpCode(BeizeOpCodes.opPop);
expect(tcpc(program), tcptc(expectedProgram));
});

test('$title - Channel', () async {
final List<String> expected = <String>['3'];
final List<String> actual = await executeTestScript(program);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,10 @@ import '../utils.dart';

Future<void> main() async {
const String title = '[Operator] Addition (1)';
final BeizeProgramConstant program =
await compileTestScript('addition_operator', 'addition_1.beize');

test('$title - Bytecode', () async {
final BeizeChunk chunk = extractChunk(program);
final BeizeTestProgram expectedChunk = BeizeTestProgram();
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(1, 1.0);
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(2, 2.0);
expectedChunk.addOpCode(BeizeOpCodes.opAdd);
expectedChunk.addOpCode(BeizeOpCodes.opDeclare);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(3, 'out');
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(4, '');
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opAdd);
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(1);
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expect(tcpc(chunk), tcptc(expectedChunk));
});
final BeizeProgramConstant program = await compileTestScript(
'addition_operator',
'addition_1.beize',
);

test('$title - Channel', () async {
final List<String> expected = <String>['3'];
Expand Down
5 changes: 5 additions & 0 deletions packages/beize_compiler/tests/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: ../analysis_options.yaml

linter:
rules:
file_names: false
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,10 @@ import '../utils.dart';

Future<void> main() async {
const String title = '[Operator] Assignment (1)';
final BeizeProgramConstant program =
await compileTestScript('assignment_operator', 'assignment_1.beize');

test('$title - Bytecode', () async {
final BeizeChunk chunk = extractChunk(program);
final BeizeTestProgram expectedChunk = BeizeTestProgram();
expectedChunk.addOpCode(BeizeOpCodes.opNull);
expectedChunk.addOpCode(BeizeOpCodes.opDeclare);
expectedChunk.addConstant(0, 'i');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(1, 'c-0');
expectedChunk.addOpCode(BeizeOpCodes.opAssign);
expectedChunk.addConstant(0, 'i');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(2, 'out');
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(0, 'i');
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(1);
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expect(tcpc(chunk), tcptc(expectedChunk));
});
final BeizeProgramConstant program = await compileTestScript(
'assignment_operator',
'assignment_1.beize',
);

test('$title - Channel', () async {
final List<String> expected = <String>['c-0'];
Expand Down
52 changes: 4 additions & 48 deletions packages/beize_compiler/tests/await_operator/await_1_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,10 @@ import '../utils.dart';

Future<void> main() async {
const String title = '[Operator] Await (1)';
final BeizeProgramConstant program =
await compileTestScript('await_operator', 'await_1.beize');

test('$title - Bytecode', () async {
final BeizeChunk chunk = extractChunk(program);
final BeizeTestProgram expectedChunk = BeizeTestProgram();
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
final BeizeTestProgram expectedChunk_0 = BeizeTestProgram();
expectedChunk_0.addOpCode(BeizeOpCodes.opConstant);
expectedChunk_0.addConstant(0, 'c-0');
expectedChunk_0.addOpCode(BeizeOpCodes.opReturn);
expectedChunk.addConstant(1, expectedChunk_0);
expectedChunk.addOpCode(BeizeOpCodes.opDeclare);
expectedChunk.addConstant(0, 'fn');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(0, 'fn');
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(0);
expectedChunk.addOpCode(BeizeOpCodes.opDeclare);
expectedChunk.addConstant(2, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(3, 'out');
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(4, 'typeof');
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(2, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(1);
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(1);
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(2, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opAwait);
expectedChunk.addOpCode(BeizeOpCodes.opAssign);
expectedChunk.addConstant(2, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(3, 'out');
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(2, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(1);
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expect(tcpc(chunk), tcptc(expectedChunk));
});
final BeizeProgramConstant program = await compileTestScript(
'await_operator',
'await_1.beize',
);

test('$title - Channel', () async {
final List<String> expected = <String>['Unawaited', 'c-0'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,9 @@ import '../utils.dart';
Future<void> main() async {
const String title = '[Operator] Bitwise AND Assignment (1)';
final BeizeProgramConstant program = await compileTestScript(
'bitwise_and_assignment_operator', 'bitwise_and_assignment_1.beize');

test('$title - Bytecode', () async {
final BeizeChunk chunk = extractChunk(program);
final BeizeTestProgram expectedChunk = BeizeTestProgram();
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(1, 0.0);
expectedChunk.addOpCode(BeizeOpCodes.opDeclare);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(2, 1.0);
expectedChunk.addOpCode(BeizeOpCodes.opBitwiseAnd);
expectedChunk.addOpCode(BeizeOpCodes.opAssign);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(3, 'out');
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(4, '');
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opAdd);
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(1);
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expect(tcpc(chunk), tcptc(expectedChunk));
});
'bitwise_and_assignment_operator',
'bitwise_and_assignment_1.beize',
);

test('$title - Channel', () async {
final List<String> expected = <String>['0'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,9 @@ import '../utils.dart';
Future<void> main() async {
const String title = '[Operator] Bitwise AND Assignment (2)';
final BeizeProgramConstant program = await compileTestScript(
'bitwise_and_assignment_operator', 'bitwise_and_assignment_2.beize');

test('$title - Bytecode', () async {
final BeizeChunk chunk = extractChunk(program);
final BeizeTestProgram expectedChunk = BeizeTestProgram();
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(1, 1.0);
expectedChunk.addOpCode(BeizeOpCodes.opDeclare);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(1, 1.0);
expectedChunk.addOpCode(BeizeOpCodes.opBitwiseAnd);
expectedChunk.addOpCode(BeizeOpCodes.opAssign);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(2, 'out');
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(3, '');
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opAdd);
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(1);
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expect(tcpc(chunk), tcptc(expectedChunk));
});
'bitwise_and_assignment_operator',
'bitwise_and_assignment_2.beize',
);

test('$title - Channel', () async {
final List<String> expected = <String>['1'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,10 @@ import '../utils.dart';

Future<void> main() async {
const String title = '[Operator] Bitwise AND (1)';
final BeizeProgramConstant program =
await compileTestScript('bitwise_and_operator', 'bitwise_and_1.beize');

test('$title - Bytecode', () async {
final BeizeChunk chunk = extractChunk(program);
final BeizeTestProgram expectedChunk = BeizeTestProgram();
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(1, 1.0);
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(1, 1.0);
expectedChunk.addOpCode(BeizeOpCodes.opBitwiseAnd);
expectedChunk.addOpCode(BeizeOpCodes.opDeclare);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(2, 'out');
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(3, '');
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opAdd);
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(1);
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expect(tcpc(chunk), tcptc(expectedChunk));
});
final BeizeProgramConstant program = await compileTestScript(
'bitwise_and_operator',
'bitwise_and_1.beize',
);

test('$title - Channel', () async {
final List<String> expected = <String>['1'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,10 @@ import '../utils.dart';

Future<void> main() async {
const String title = '[Operator] Bitwise AND (2)';
final BeizeProgramConstant program =
await compileTestScript('bitwise_and_operator', 'bitwise_and_2.beize');

test('$title - Bytecode', () async {
final BeizeChunk chunk = extractChunk(program);
final BeizeTestProgram expectedChunk = BeizeTestProgram();
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(1, 1.0);
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(2, 2.0);
expectedChunk.addOpCode(BeizeOpCodes.opBitwiseAnd);
expectedChunk.addOpCode(BeizeOpCodes.opDeclare);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(3, 'out');
expectedChunk.addOpCode(BeizeOpCodes.opConstant);
expectedChunk.addConstant(4, '');
expectedChunk.addOpCode(BeizeOpCodes.opLookup);
expectedChunk.addConstant(0, 'result');
expectedChunk.addOpCode(BeizeOpCodes.opAdd);
expectedChunk.addOpCode(BeizeOpCodes.opCall);
expectedChunk.addCode(1);
expectedChunk.addOpCode(BeizeOpCodes.opPop);
expect(tcpc(chunk), tcptc(expectedChunk));
});
final BeizeProgramConstant program = await compileTestScript(
'bitwise_and_operator',
'bitwise_and_2.beize',
);

test('$title - Channel', () async {
final List<String> expected = <String>['0'];
Expand Down
Loading

0 comments on commit b09f257

Please sign in to comment.