Skip to content

Commit 258b581

Browse files
committed
[null] Remove inline comments from code and tests
1 parent 84c5158 commit 258b581

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

src/store/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ import {PoolFunctions, getPoolFunctions} from '../common/pool.ts';
117117
import {IdSet, IdSet2, IdSet3, IdSet4, setAdd, setNew} from '../common/set.ts';
118118
import {
119119
ADD,
120+
ALLOW_NULL,
120121
CELL,
121122
CELL_IDS,
122123
DEFAULT,
123-
ALLOW_NULL,
124124
HAS,
125125
LISTENER,
126126
NUMBER,
@@ -247,11 +247,9 @@ export const createStore: typeof createStoreDecl = (): Store => {
247247
return false;
248248
}
249249
const defaultValue = schema[DEFAULT];
250-
// If default is null, allowNull must be true
251250
if (defaultValue === null && !schema[ALLOW_NULL]) {
252251
return false;
253252
}
254-
// If default is provided and not null, check type matches
255253
if (defaultValue !== null && getCellOrValueType(defaultValue) != type) {
256254
objDel(schema as any, DEFAULT);
257255
}

test/unit/core/store/null-values.test.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {beforeEach, describe, expect, test} from 'vitest';
21
import type {Store} from 'tinybase';
32
import {createStore} from 'tinybase';
3+
import {beforeEach, describe, expect, test} from 'vitest';
44

55
describe('Null values', () => {
66
let store: Store;
@@ -12,7 +12,7 @@ describe('Null values', () => {
1212
test('Setting and getting null', () => {
1313
store.setCell('t1', 'r1', 'c1', null);
1414
expect(store.getCell('t1', 'r1', 'c1')).toBe(null);
15-
expect(store.hasCell('t1', 'r1', 'c1')).toBe(true); // Cell EXISTS
15+
expect(store.hasCell('t1', 'r1', 'c1')).toBe(true);
1616
});
1717

1818
test('Null vs undefined', () => {
@@ -22,7 +22,7 @@ describe('Null values', () => {
2222

2323
store.delCell('t1', 'r1', 'c1');
2424
expect(store.getCell('t1', 'r1', 'c1')).toBeUndefined();
25-
expect(store.hasCell('t1', 'r1', 'c1')).toBe(false); // Doesn't exist
25+
expect(store.hasCell('t1', 'r1', 'c1')).toBe(false);
2626
});
2727

2828
test('Setting null value', () => {
@@ -103,21 +103,21 @@ describe('Null with schemas', () => {
103103
},
104104
});
105105

106-
store.setCell('t1', 'r1', 'c1', null); // ✓ Allowed
106+
store.setCell('t1', 'r1', 'c1', null);
107107
expect(store.getCell('t1', 'r1', 'c1')).toBe(null);
108108

109-
store.setCell('t1', 'r1', 'c1', 'hello'); // ✓ Also allowed
109+
store.setCell('t1', 'r1', 'c1', 'hello');
110110
expect(store.getCell('t1', 'r1', 'c1')).toBe('hello');
111111
});
112112

113113
test('Schema with allowNull: false (default)', () => {
114114
store.setTablesSchema({
115115
t1: {
116-
c1: {type: 'string'}, // allowNull defaults to false
116+
c1: {type: 'string'},
117117
},
118118
});
119119

120-
store.setCell('t1', 'r1', 'c1', null); // ✗ Rejected
120+
store.setCell('t1', 'r1', 'c1', null);
121121
expect(store.hasCell('t1', 'r1', 'c1')).toBe(false);
122122
});
123123

@@ -128,21 +128,18 @@ describe('Null with schemas', () => {
128128
},
129129
});
130130

131-
store.setRow('t1', 'r1', {}); // c1 gets default null
131+
store.setRow('t1', 'r1', {});
132132
expect(store.getCell('t1', 'r1', 'c1')).toBe(null);
133133
});
134134

135135
test('Schema with default: null requires allowNull: true', () => {
136-
// This should fail schema validation
137136
const result = store.setTablesSchema({
138137
t1: {
139-
c1: {type: 'string', default: null}, // Missing allowNull: true
138+
c1: {type: 'string', default: null},
140139
},
141140
});
142141

143-
// Schema validation should fail
144142
expect(result).toBe(store);
145-
// The schema should not be set
146143
expect(store.getTablesSchemaJson()).toBe('{}');
147144
});
148145

@@ -151,43 +148,42 @@ describe('Null with schemas', () => {
151148
v1: {type: 'number', allowNull: true},
152149
});
153150

154-
store.setValue('v1', null); // ✓ Allowed
151+
store.setValue('v1', null);
155152
expect(store.getValue('v1')).toBe(null);
156153

157-
store.setValue('v1', 42); // ✓ Also allowed
154+
store.setValue('v1', 42);
158155
expect(store.getValue('v1')).toBe(42);
159156
});
160157

161158
test('Values schema with allowNull: false (default)', () => {
162159
store.setValuesSchema({
163-
v1: {type: 'number'}, // allowNull defaults to false
160+
v1: {type: 'number'},
164161
});
165162

166-
store.setValue('v1', null); // ✗ Rejected
163+
store.setValue('v1', null);
167164
expect(store.hasValue('v1')).toBe(false);
168165
});
169166

170167
test('Multiple types with different null settings', () => {
171168
store.setTablesSchema({
172169
t1: {
173-
name: {type: 'string'}, // null not allowed
174-
age: {type: 'number', allowNull: true}, // null allowed
175-
active: {type: 'boolean', default: true}, // null not allowed
170+
name: {type: 'string'},
171+
age: {type: 'number', allowNull: true},
172+
active: {type: 'boolean', default: true},
176173
},
177174
});
178175

179176
store.setRow('t1', 'r1', {
180177
name: 'Alice',
181-
age: null, // ✓
178+
age: null,
182179
active: true,
183180
});
184181

185182
expect(store.getCell('t1', 'r1', 'name')).toBe('Alice');
186183
expect(store.getCell('t1', 'r1', 'age')).toBe(null);
187184
expect(store.getCell('t1', 'r1', 'active')).toBe(true);
188185

189-
// Try to set null on non-nullable field
190-
store.setCell('t1', 'r1', 'name', null); // ✗ Rejected
191-
expect(store.getCell('t1', 'r1', 'name')).toBe('Alice'); // Unchanged
186+
store.setCell('t1', 'r1', 'name', null);
187+
expect(store.getCell('t1', 'r1', 'name')).toBe('Alice');
192188
});
193189
});

0 commit comments

Comments
 (0)