@a2ui-sdk/utils 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,180 +0,0 @@
1
- /**
2
- * dataBinding Tests
3
- *
4
- * Tests for data binding utility functions used in A2UI 0.9.
5
- */
6
- import { describe, it, expect } from 'vitest';
7
- import { isPathBinding, isFunctionCall, resolveValue, resolveString, resolveContext, } from './dataBinding.js';
8
- describe('dataBinding', () => {
9
- const testModel = {
10
- user: {
11
- name: 'John',
12
- age: 30,
13
- active: true,
14
- },
15
- items: ['a', 'b', 'c'],
16
- count: 42,
17
- };
18
- describe('isPathBinding', () => {
19
- it('should return true for path binding object', () => {
20
- expect(isPathBinding({ path: '/user/name' })).toBe(true);
21
- });
22
- it('should return true for relative path binding', () => {
23
- expect(isPathBinding({ path: 'name' })).toBe(true);
24
- });
25
- it('should return false for string literal', () => {
26
- expect(isPathBinding('Hello')).toBe(false);
27
- });
28
- it('should return false for number literal', () => {
29
- expect(isPathBinding(42)).toBe(false);
30
- });
31
- it('should return false for boolean literal', () => {
32
- expect(isPathBinding(true)).toBe(false);
33
- });
34
- it('should return false for function call', () => {
35
- expect(isPathBinding({ call: 'required' })).toBe(false);
36
- });
37
- it('should return false for undefined', () => {
38
- expect(isPathBinding(undefined)).toBe(false);
39
- });
40
- it('should return false for null', () => {
41
- expect(isPathBinding(null)).toBe(false);
42
- });
43
- it('should return false for object without path property', () => {
44
- expect(isPathBinding({ other: 'value' })).toBe(false);
45
- });
46
- });
47
- describe('isFunctionCall', () => {
48
- it('should return true for function call object', () => {
49
- expect(isFunctionCall({ call: 'required' })).toBe(true);
50
- });
51
- it('should return true for function call with args', () => {
52
- expect(isFunctionCall({ call: 'regex', args: { pattern: '.*' } })).toBe(true);
53
- });
54
- it('should return false for path binding', () => {
55
- expect(isFunctionCall({ path: '/user/name' })).toBe(false);
56
- });
57
- it('should return false for string literal', () => {
58
- expect(isFunctionCall('Hello')).toBe(false);
59
- });
60
- it('should return false for undefined', () => {
61
- expect(isFunctionCall(undefined)).toBe(false);
62
- });
63
- it('should return false for null', () => {
64
- expect(isFunctionCall(null)).toBe(false);
65
- });
66
- });
67
- // Note: hasInterpolation is now an internal function (not exported)
68
- // Tests for interpolation behavior are in interpolation.test.ts
69
- describe('resolveValue', () => {
70
- it('should resolve string literal', () => {
71
- expect(resolveValue('Hello', testModel)).toBe('Hello');
72
- });
73
- it('should resolve number literal', () => {
74
- expect(resolveValue(42, testModel)).toBe(42);
75
- });
76
- it('should resolve boolean literal', () => {
77
- expect(resolveValue(true, testModel)).toBe(true);
78
- expect(resolveValue(false, testModel)).toBe(false);
79
- });
80
- it('should resolve absolute path binding', () => {
81
- expect(resolveValue({ path: '/user/name' }, testModel)).toBe('John');
82
- });
83
- it('should resolve nested path binding', () => {
84
- expect(resolveValue({ path: '/user/age' }, testModel)).toBe(30);
85
- });
86
- it('should resolve relative path binding with base path', () => {
87
- expect(resolveValue({ path: 'name' }, testModel, '/user')).toBe('John');
88
- });
89
- it('should resolve absolute path even with base path', () => {
90
- expect(resolveValue({ path: '/count' }, testModel, '/user')).toBe(42);
91
- });
92
- it('should return default for undefined value', () => {
93
- expect(resolveValue(undefined, testModel, null, 'default')).toBe('default');
94
- });
95
- it('should return default for null value', () => {
96
- expect(resolveValue(null, testModel, null, 'default')).toBe('default');
97
- });
98
- it('should return default for non-existent path', () => {
99
- expect(resolveValue({ path: '/nonexistent' }, testModel, null, 'default')).toBe('default');
100
- });
101
- it('should return default for function call', () => {
102
- expect(resolveValue({ call: 'required' }, testModel, null, 'default')).toBe('default');
103
- });
104
- it('should resolve array element by index', () => {
105
- expect(resolveValue({ path: '/items/0' }, testModel)).toBe('a');
106
- });
107
- });
108
- describe('resolveString', () => {
109
- it('should resolve string literal', () => {
110
- expect(resolveString('Hello', testModel)).toBe('Hello');
111
- });
112
- it('should resolve path binding to string', () => {
113
- expect(resolveString({ path: '/user/name' }, testModel)).toBe('John');
114
- });
115
- it('should convert number to string', () => {
116
- expect(resolveString({ path: '/count' }, testModel)).toBe('42');
117
- });
118
- it('should return default for undefined', () => {
119
- expect(resolveString(undefined, testModel, null, 'default')).toBe('default');
120
- });
121
- it('should return empty string as default', () => {
122
- expect(resolveString(undefined, testModel)).toBe('');
123
- });
124
- });
125
- describe('resolveContext', () => {
126
- it('should resolve context with literal values', () => {
127
- const context = {
128
- name: 'John',
129
- age: 30,
130
- active: true,
131
- };
132
- expect(resolveContext(context, testModel)).toEqual({
133
- name: 'John',
134
- age: 30,
135
- active: true,
136
- });
137
- });
138
- it('should resolve context with path bindings', () => {
139
- const context = {
140
- name: { path: '/user/name' },
141
- age: { path: '/user/age' },
142
- };
143
- expect(resolveContext(context, testModel)).toEqual({
144
- name: 'John',
145
- age: 30,
146
- });
147
- });
148
- it('should resolve context with mixed values', () => {
149
- const context = {
150
- userName: { path: '/user/name' },
151
- action: 'submit',
152
- count: 42,
153
- };
154
- expect(resolveContext(context, testModel)).toEqual({
155
- userName: 'John',
156
- action: 'submit',
157
- count: 42,
158
- });
159
- });
160
- it('should resolve relative paths with base path', () => {
161
- const context = {
162
- name: { path: 'name' },
163
- };
164
- expect(resolveContext(context, testModel, '/user')).toEqual({
165
- name: 'John',
166
- });
167
- });
168
- it('should return empty object for undefined context', () => {
169
- expect(resolveContext(undefined, testModel)).toEqual({});
170
- });
171
- it('should handle non-existent paths', () => {
172
- const context = {
173
- name: { path: '/nonexistent' },
174
- };
175
- expect(resolveContext(context, testModel)).toEqual({
176
- name: undefined,
177
- });
178
- });
179
- });
180
- });
@@ -1,4 +0,0 @@
1
- /**
2
- * Tests for the evaluator.
3
- */
4
- export {};