Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions bindings/dart/test/create_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,161 @@ void main() {
}
});
});

// Edge case tests

group('Create Single Element Vector', () {
test('creates element with single element vector', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
db.createElement('Configuration', {'label': 'Test Config'});
final id = db.createElement('Collection', {
'label': 'Item 1',
'value_int': [42],
});
expect(id, greaterThan(0));

final result = db.readVectorIntegersById('Collection', 'value_int', 1);
expect(result.length, equals(1));
expect(result[0], equals(42));
} finally {
db.close();
}
});
});

group('Create Large Vector', () {
test('creates element with 100+ element vector', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
db.createElement('Configuration', {'label': 'Test Config'});

final largeVector = List.generate(150, (i) => i + 1);
final id = db.createElement('Collection', {
'label': 'Item 1',
'value_int': largeVector,
});
expect(id, greaterThan(0));

final result = db.readVectorIntegersById('Collection', 'value_int', 1);
expect(result.length, equals(150));
expect(result, equals(largeVector));
} finally {
db.close();
}
});
});

group('Create Invalid Collection', () {
test('throws on nonexistent collection', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'basic.sql'),
);
try {
expect(
() => db.createElement('NonexistentCollection', {'label': 'Test'}),
throwsA(isA<DatabaseException>()),
);
} finally {
db.close();
}
});
});

group('Create With Only Required Label', () {
test('creates element with only required label', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
db.createElement('Configuration', {'label': 'Test Config'});

// Create with only required label, no optional attributes
final id = db.createElement('Collection', {'label': 'Minimal Item'});
expect(id, greaterThan(0));

final labels = db.readScalarStrings('Collection', 'label');
expect(labels.length, equals(1));
expect(labels[0], equals('Minimal Item'));
} finally {
db.close();
}
});
});

group('Create With Multiple Sets', () {
test('creates element with set containing multiple values', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
db.createElement('Configuration', {'label': 'Test Config'});

final id = db.createElement('Collection', {
'label': 'Item 1',
'tag': ['a', 'b', 'c', 'd', 'e'],
});
expect(id, greaterThan(0));

final result = db.readSetStringsById('Collection', 'tag', 1);
expect(result.length, equals(5));
expect(result..sort(), equals(['a', 'b', 'c', 'd', 'e']));
} finally {
db.close();
}
});
});

group('Create Duplicate Label Rejected', () {
test('throws on duplicate label', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'basic.sql'),
);
try {
db.createElement('Configuration', {'label': 'Config 1'});

// Trying to create with same label should fail
expect(
() => db.createElement('Configuration', {'label': 'Config 1'}),
throwsA(isA<DatabaseException>()),
);
} finally {
db.close();
}
});
});

group('Create With Float Vector', () {
test('creates element with float vector', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
db.createElement('Configuration', {'label': 'Test Config'});

final id = db.createElement('Collection', {
'label': 'Item 1',
'value_float': [1.1, 2.2, 3.3],
});
expect(id, greaterThan(0));

final result = db.readVectorDoublesById('Collection', 'value_float', 1);
expect(result.length, equals(3));
expect(result, equals([1.1, 2.2, 3.3]));
} finally {
db.close();
}
});
});
}
201 changes: 201 additions & 0 deletions bindings/dart/test/lua_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,205 @@ void main() {
}
});
});

// Error handling tests

group('LuaRunner Undefined Variable', () {
test('throws on undefined variable access', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
final lua = LuaRunner(db);
try {
expect(
() => lua.run('print(undefined_variable.field)'),
throwsA(isA<LuaException>()),
);
} finally {
lua.dispose();
}
} finally {
db.close();
}
});
});

group('LuaRunner Create Invalid Collection', () {
test('throws on nonexistent collection in script', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
final lua = LuaRunner(db);
try {
lua.run('db:create_element("Configuration", { label = "Test Config" })');
expect(
() => lua.run('db:create_element("NonexistentCollection", { label = "Item" })'),
throwsA(isA<LuaException>()),
);
} finally {
lua.dispose();
}
} finally {
db.close();
}
});
});

group('LuaRunner Empty Script', () {
test('runs empty script successfully', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
final lua = LuaRunner(db);
try {
// Empty script should succeed without error
lua.run('');
// If we get here, the test passed
expect(true, isTrue);
} finally {
lua.dispose();
}
} finally {
db.close();
}
});
});

group('LuaRunner Comment Only Script', () {
test('runs comment-only script successfully', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
final lua = LuaRunner(db);
try {
// Comment-only script should succeed
lua.run('-- this is just a comment');
expect(true, isTrue);
} finally {
lua.dispose();
}
} finally {
db.close();
}
});
});

group('LuaRunner Read Integers', () {
test('reads scalar integers in Lua script', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
db.createElement('Configuration', {'label': 'Config'});
db.createElement('Collection', {'label': 'Item 1', 'some_integer': 100});
db.createElement('Collection', {'label': 'Item 2', 'some_integer': 200});

final lua = LuaRunner(db);
try {
lua.run('''
local ints = db:read_scalar_integers("Collection", "some_integer")
assert(#ints == 2, "Expected 2 integers")
assert(ints[1] == 100, "First integer mismatch")
assert(ints[2] == 200, "Second integer mismatch")
''');
} finally {
lua.dispose();
}
} finally {
db.close();
}
});
});

group('LuaRunner Read Doubles', () {
test('reads scalar doubles in Lua script', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
db.createElement('Configuration', {'label': 'Config'});
db.createElement('Collection', {'label': 'Item 1', 'some_float': 1.5});
db.createElement('Collection', {'label': 'Item 2', 'some_float': 2.5});

final lua = LuaRunner(db);
try {
lua.run('''
local floats = db:read_scalar_doubles("Collection", "some_float")
assert(#floats == 2, "Expected 2 doubles")
assert(floats[1] == 1.5, "First double mismatch")
assert(floats[2] == 2.5, "Second double mismatch")
''');
} finally {
lua.dispose();
}
} finally {
db.close();
}
});
});

group('LuaRunner Read Vectors', () {
test('reads vector integers in Lua script', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
db.createElement('Configuration', {'label': 'Config'});
db.createElement('Collection', {'label': 'Item 1', 'value_int': [1, 2, 3]});

final lua = LuaRunner(db);
try {
lua.run('''
local vectors = db:read_vector_integers("Collection", "value_int")
assert(#vectors == 1, "Expected 1 vector")
assert(#vectors[1] == 3, "Expected 3 elements in vector")
assert(vectors[1][1] == 1, "First element mismatch")
assert(vectors[1][2] == 2, "Second element mismatch")
assert(vectors[1][3] == 3, "Third element mismatch")
''');
} finally {
lua.dispose();
}
} finally {
db.close();
}
});
});

group('LuaRunner Create With Vector', () {
test('creates element with vector in Lua script', () {
final db = Database.fromSchema(
':memory:',
path.join(testsPath, 'schemas', 'valid', 'collections.sql'),
);
try {
final lua = LuaRunner(db);
try {
lua.run('''
db:create_element("Configuration", { label = "Config" })
db:create_element("Collection", { label = "Item 1", value_int = {10, 20, 30} })
''');

final result = db.readVectorIntegers('Collection', 'value_int');
expect(result.length, equals(1));
expect(result[0], equals([10, 20, 30]));
} finally {
lua.dispose();
}
} finally {
db.close();
}
});
});
}
Loading
Loading