bare-script 3.0.15 → 3.1.0
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.
- package/lib/bare.js +47 -4
- package/lib/include/args.mds +344 -0
- package/lib/include/forms.mds +79 -0
- package/lib/include/markdownUp.bare +466 -0
- package/lib/include/pager.mds +235 -0
- package/lib/include/unittest.mds +191 -0
- package/lib/include/unittestMock.mds +462 -0
- package/package.json +2 -2
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Licensed under the MIT License
|
|
2
|
+
# https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Include sentinel
|
|
6
|
+
if systemGlobalGet('unittestSentinel'):
|
|
7
|
+
return
|
|
8
|
+
endif
|
|
9
|
+
unittestSentinel = true
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Test statistics
|
|
13
|
+
unittestTests = objectNew()
|
|
14
|
+
unittestWarnings = arrayNew()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# $function: unittestRunTest
|
|
18
|
+
# $group: unittest.mds
|
|
19
|
+
# $doc: Run a unit test
|
|
20
|
+
# $arg testName: The test function name
|
|
21
|
+
function unittestRunTest(testName):
|
|
22
|
+
testFn = unittestRunTestHelper(testName)
|
|
23
|
+
if testFn:
|
|
24
|
+
testFn()
|
|
25
|
+
systemGlobalSet('unittestTestName', null)
|
|
26
|
+
endif
|
|
27
|
+
endfunction
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# $function: unittestRunTestAsync
|
|
31
|
+
# $group: unittest.mds
|
|
32
|
+
# $doc: Run an asyncronous unit test
|
|
33
|
+
# $arg testName: The test function name
|
|
34
|
+
async function unittestRunTestAsync(testName):
|
|
35
|
+
testFn = unittestRunTestHelper(testName)
|
|
36
|
+
if testFn:
|
|
37
|
+
testFn()
|
|
38
|
+
systemGlobalSet('unittestTestName', null)
|
|
39
|
+
endif
|
|
40
|
+
endfunction
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# unittestRunTest helper function
|
|
44
|
+
function unittestRunTestHelper(testName):
|
|
45
|
+
# Single test argument?
|
|
46
|
+
if vTest != null && vTest != testName:
|
|
47
|
+
return null
|
|
48
|
+
endif
|
|
49
|
+
|
|
50
|
+
# Test run multiple times?
|
|
51
|
+
if objectHas(unittestTests, testName):
|
|
52
|
+
arrayPush(unittestWarnings, 'Test "' + testName + '" run multiple times')
|
|
53
|
+
return null
|
|
54
|
+
endif
|
|
55
|
+
|
|
56
|
+
# Get the test func
|
|
57
|
+
testFn = systemGlobalGet(testName)
|
|
58
|
+
if testFn == null:
|
|
59
|
+
arrayPush(unittestWarnings, 'Test "' + testName + '" not found')
|
|
60
|
+
return null
|
|
61
|
+
endif
|
|
62
|
+
|
|
63
|
+
# Add the unit test result array
|
|
64
|
+
testFailures = arrayNew()
|
|
65
|
+
objectSet(unittestTests, testName, testFailures)
|
|
66
|
+
systemGlobalSet('unittestTestName', testName)
|
|
67
|
+
|
|
68
|
+
return testFn
|
|
69
|
+
endfunction
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# $function: unittestReport
|
|
73
|
+
# $group: unittest.mds
|
|
74
|
+
# $doc: Render the unit test report
|
|
75
|
+
# $return: The number of unit test failures
|
|
76
|
+
function unittestReport():
|
|
77
|
+
# Compute test statistics
|
|
78
|
+
testNames = arraySort(objectKeys(unittestTests))
|
|
79
|
+
testCount = arrayLength(testNames)
|
|
80
|
+
testFailCount = 0
|
|
81
|
+
for testName in testNames:
|
|
82
|
+
testFailures = objectGet(unittestTests, testName)
|
|
83
|
+
if arrayLength(testFailures):
|
|
84
|
+
testFailCount = testFailCount + 1
|
|
85
|
+
endif
|
|
86
|
+
endfor
|
|
87
|
+
testPassCount = testCount - testFailCount
|
|
88
|
+
|
|
89
|
+
# Report statistics
|
|
90
|
+
markdownPrint('', 'Ran ' + testCount + ' tests - ' + testPassCount + ' passed, ' + testFailCount + ' failed')
|
|
91
|
+
if vTest != null:
|
|
92
|
+
testURL = if(vTestArgs != null, '#' + vTestArgs, '#var=')
|
|
93
|
+
markdownPrint('([all tests](' + testURL + '))')
|
|
94
|
+
endif
|
|
95
|
+
|
|
96
|
+
# Report any warnings
|
|
97
|
+
testWarningCount = arrayLength(unittestWarnings)
|
|
98
|
+
if testWarningCount:
|
|
99
|
+
markdownPrint('', '## Warnings')
|
|
100
|
+
for warning in unittestWarnings:
|
|
101
|
+
markdownPrint('', '- ' + markdownEscape(warning))
|
|
102
|
+
endfor
|
|
103
|
+
endif
|
|
104
|
+
|
|
105
|
+
# Report the failing tests
|
|
106
|
+
if testFailCount:
|
|
107
|
+
markdownPrint('', '## Failing Tests')
|
|
108
|
+
for testName in testNames:
|
|
109
|
+
testFailures = objectGet(unittestTests, testName)
|
|
110
|
+
if arrayLength(testFailures):
|
|
111
|
+
testURL = '#' + if(vTestArgs != null, vTestArgs + '&', '') + "var.vTest='" + urlEncodeComponent(testName) + "'"
|
|
112
|
+
failureLines = arrayNew('', '[' + markdownEscape(testName) + '](' + testURL + ") - FAIL")
|
|
113
|
+
for errorLines in testFailures:
|
|
114
|
+
for errorLine, ixErrorLine in errorLines:
|
|
115
|
+
if ixErrorLine == 0:
|
|
116
|
+
arrayPush(failureLines, '')
|
|
117
|
+
arrayPush(failureLines, '- ' + errorLine)
|
|
118
|
+
else:
|
|
119
|
+
arrayPush(failureLines, ' ' + errorLine)
|
|
120
|
+
endif
|
|
121
|
+
endfor
|
|
122
|
+
endfor
|
|
123
|
+
markdownPrint(failureLines)
|
|
124
|
+
endif
|
|
125
|
+
endfor
|
|
126
|
+
endif
|
|
127
|
+
|
|
128
|
+
# Report the passing tests
|
|
129
|
+
if testPassCount:
|
|
130
|
+
markdownPrint('', '## Passing Tests')
|
|
131
|
+
for testName in testNames:
|
|
132
|
+
testFailures = objectGet(unittestTests, testName)
|
|
133
|
+
if !arrayLength(testFailures):
|
|
134
|
+
testURL = '#' + if(vTestArgs != null, vTestArgs + '&', '') + "var.vTest='" + urlEncodeComponent(testName) + "'"
|
|
135
|
+
markdownPrint('', '[' + markdownEscape(testName) + '](' + testURL + ") - OK")
|
|
136
|
+
endif
|
|
137
|
+
endfor
|
|
138
|
+
endif
|
|
139
|
+
|
|
140
|
+
return testWarningCount + testFailCount
|
|
141
|
+
endfunction
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# $function: unittestEqual
|
|
145
|
+
# $group: unittest.mds
|
|
146
|
+
# $doc: Assert an actual value is equal to the expected value
|
|
147
|
+
# $arg actual: The actual value
|
|
148
|
+
# $arg expected: The expected value
|
|
149
|
+
# $arg description: The description of the assertion
|
|
150
|
+
function unittestEqual(actual, expected, description):
|
|
151
|
+
if actual != expected:
|
|
152
|
+
unittestRecordError(jsonStringify(actual), jsonStringify(expected), description)
|
|
153
|
+
endif
|
|
154
|
+
endfunction
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
# $function: unittestDeepEqual
|
|
158
|
+
# $group: unittest.mds
|
|
159
|
+
# $doc: Assert an actual value is *deeply* equal to the expected value
|
|
160
|
+
# $arg actual: The actual value
|
|
161
|
+
# $arg expected: The expected value
|
|
162
|
+
# $arg description: The description of the assertion
|
|
163
|
+
function unittestDeepEqual(actual, expected, description):
|
|
164
|
+
actualJSON = jsonStringify(actual)
|
|
165
|
+
expectedJSON = jsonStringify(expected)
|
|
166
|
+
if actualJSON != expectedJSON:
|
|
167
|
+
unittestRecordError(actualJSON, expectedJSON, description)
|
|
168
|
+
endif
|
|
169
|
+
endfunction
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
# Helper function to record a unit test error
|
|
173
|
+
function unittestRecordError(actualStr, expectedStr, description):
|
|
174
|
+
testFailures = objectGet(unittestTests, unittestTestName)
|
|
175
|
+
errorLines = arrayNew( \
|
|
176
|
+
'~~~', \
|
|
177
|
+
actualStr, \
|
|
178
|
+
'~~~', \
|
|
179
|
+
'', \
|
|
180
|
+
'!=', \
|
|
181
|
+
'', \
|
|
182
|
+
'~~~', \
|
|
183
|
+
expectedStr, \
|
|
184
|
+
'~~~' \
|
|
185
|
+
)
|
|
186
|
+
if description != null:
|
|
187
|
+
arrayPush(testFailures, arrayExtend(arrayNew(markdownEscape(description), errorLines)))
|
|
188
|
+
else:
|
|
189
|
+
arrayPush(testFailures, errorLines)
|
|
190
|
+
endif
|
|
191
|
+
endfunction
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
# Licensed under the MIT License
|
|
2
|
+
# https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Include sentinel
|
|
6
|
+
if systemGlobalGet('unittestMockSentinel'):
|
|
7
|
+
return
|
|
8
|
+
endif
|
|
9
|
+
unittestMockSentinel = true
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Constants
|
|
13
|
+
unittestMockPixelsPerPoint = 4 / 3
|
|
14
|
+
unittestMockDefaultFontSizePx = 12 * unittestMockPixelsPerPoint
|
|
15
|
+
unittestMockFontWidthRatio = 0.6
|
|
16
|
+
unittestMockWindowHeight = 768
|
|
17
|
+
unittestMockWindowWidth = 1024
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# The mocked MarkdownUp state
|
|
21
|
+
unittestMockCalls = arrayNew()
|
|
22
|
+
unittestMockFunctions = objectNew()
|
|
23
|
+
unittestMockStateDefault = objectNew( \
|
|
24
|
+
'drawingFontSizePx', unittestMockDefaultFontSizePx, \
|
|
25
|
+
'drawingHeight', 480, \
|
|
26
|
+
'drawingWidth', 640, \
|
|
27
|
+
'localStorage', objectNew(), \
|
|
28
|
+
'sessionStorage', objectNew(), \
|
|
29
|
+
'windowClipboard', '' \
|
|
30
|
+
)
|
|
31
|
+
unittestMockState = objectCopy(unittestMockStateDefault)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# $function: unittestMockAll
|
|
35
|
+
# $group: unittestMock.mds
|
|
36
|
+
# $doc: Start mocking all BareScript and MarkdownUp library functions with externalities.
|
|
37
|
+
# $doc: To stop mocking, call the [unittestMockEnd](#var.vGroup='unittestMock.mds'&unittestmockend) function.
|
|
38
|
+
# $arg data: Optional (default is null). The map of function name to mock function data.
|
|
39
|
+
# $arg data: The following functions make use of mock data:
|
|
40
|
+
# $arg data: - **documentInputValue** - map of id to return value
|
|
41
|
+
# $arg data: - **markdownParse** - array of return values
|
|
42
|
+
# $arg data: - **markdownTitle** - array of return values
|
|
43
|
+
# $arg data: - **systemFetch** - map of URL to response text
|
|
44
|
+
function unittestMockAll(data):
|
|
45
|
+
# Data
|
|
46
|
+
unittestMockOneGeneric('dataLineChart')
|
|
47
|
+
unittestMockOneGeneric('dataTable')
|
|
48
|
+
|
|
49
|
+
# Document
|
|
50
|
+
unittestMockOne('documentFontSize', unittestMock_documentFontSize)
|
|
51
|
+
unittestMockOne('documentInputValue', systemPartial(unittestMock_documentInputValue, if(data != null, objectGet(data, 'documentInputValue'))))
|
|
52
|
+
unittestMockOneGeneric('documentSetFocus')
|
|
53
|
+
unittestMockOneGeneric('documentSetReset')
|
|
54
|
+
unittestMockOneGeneric('documentSetTitle')
|
|
55
|
+
unittestMockOne('documentURL', unittestMock_documentURL)
|
|
56
|
+
|
|
57
|
+
# Drawing
|
|
58
|
+
unittestMockOneGeneric('drawArc')
|
|
59
|
+
unittestMockOneGeneric('drawCircle')
|
|
60
|
+
unittestMockOneGeneric('drawClose')
|
|
61
|
+
unittestMockOneGeneric('drawEllipse')
|
|
62
|
+
unittestMockOneGeneric('drawHLine')
|
|
63
|
+
unittestMockOne('drawHeight', unittestMock_drawHeight)
|
|
64
|
+
unittestMockOneGeneric('drawImage')
|
|
65
|
+
unittestMockOneGeneric('drawLine')
|
|
66
|
+
unittestMockOneGeneric('drawMove')
|
|
67
|
+
unittestMockOne('drawNew', unittestMock_drawNew)
|
|
68
|
+
unittestMockOneGeneric('drawOnClick')
|
|
69
|
+
unittestMockOneGeneric('drawPathRect')
|
|
70
|
+
unittestMockOneGeneric('drawRect')
|
|
71
|
+
unittestMockOneGeneric('drawStyle')
|
|
72
|
+
unittestMockOneGeneric('drawText')
|
|
73
|
+
unittestMockOne('drawTextHeight', unittestMock_drawTextHeight)
|
|
74
|
+
unittestMockOne('drawTextStyle', unittestMock_drawTextStyle)
|
|
75
|
+
unittestMockOne('drawTextWidth', unittestMock_drawTextWidth)
|
|
76
|
+
unittestMockOneGeneric('drawVLine')
|
|
77
|
+
unittestMockOne('drawWidth', unittestMock_drawWidth)
|
|
78
|
+
|
|
79
|
+
# Element Model
|
|
80
|
+
unittestMockOneGeneric('elementModelRender')
|
|
81
|
+
|
|
82
|
+
# Local Storage
|
|
83
|
+
unittestMockOne('localStorageClear', unittestMock_localStorageClear)
|
|
84
|
+
unittestMockOne('localStorageGet', unittestMock_localStorageGet)
|
|
85
|
+
unittestMockOne('localStorageRemove', unittestMock_localStorageRemove)
|
|
86
|
+
unittestMockOne('localStorageSet', unittestMock_localStorageSet)
|
|
87
|
+
|
|
88
|
+
# Markdown
|
|
89
|
+
unittestMockOne('markdownEscape', unittestMock_markdownEscape)
|
|
90
|
+
unittestMockOne('markdownHeaderId', unittestMock_markdownHeaderId)
|
|
91
|
+
unittestMockOne('markdownParse', systemPartial(unittestMock_markdownParse, if(data != null, objectGet(data, 'markdownParse'))))
|
|
92
|
+
unittestMockOneGeneric('markdownPrint')
|
|
93
|
+
unittestMockOne('markdownTitle', systemPartial(unittestMock_markdownTitle, if(data != null, objectGet(data, 'markdownTitle'))))
|
|
94
|
+
|
|
95
|
+
# Schema
|
|
96
|
+
unittestMockOne('schemaElements', unittestMock_schemaElements)
|
|
97
|
+
|
|
98
|
+
# Session Storage
|
|
99
|
+
unittestMockOne('sessionStorageClear', unittestMock_sessionStorageClear)
|
|
100
|
+
unittestMockOne('sessionStorageGet', unittestMock_sessionStorageGet)
|
|
101
|
+
unittestMockOne('sessionStorageRemove', unittestMock_sessionStorageRemove)
|
|
102
|
+
unittestMockOne('sessionStorageSet', unittestMock_sessionStorageSet)
|
|
103
|
+
|
|
104
|
+
# System
|
|
105
|
+
unittestMockOne('systemFetch', systemPartial(unittestMock_systemFetch, if(data != null, objectGet(data, 'systemFetch'))))
|
|
106
|
+
unittestMockOneGeneric('systemLog')
|
|
107
|
+
unittestMockOneGeneric('systemLogDebug')
|
|
108
|
+
|
|
109
|
+
# URL
|
|
110
|
+
unittestMockOne('urlObjectCreate', unittestMock_urlObjectCreate)
|
|
111
|
+
|
|
112
|
+
# Window
|
|
113
|
+
unittestMockOne('windowClipboardRead', unittestMock_windowClipboardRead)
|
|
114
|
+
unittestMockOne('windowClipboardWrite', unittestMock_windowClipboardWrite)
|
|
115
|
+
unittestMockOne('windowHeight', unittestMock_windowHeight)
|
|
116
|
+
unittestMockOneGeneric('windowSetLocation')
|
|
117
|
+
unittestMockOneGeneric('windowSetResize')
|
|
118
|
+
unittestMockOneGeneric('windowSetTimeout')
|
|
119
|
+
unittestMockOne('windowWidth', unittestMock_windowWidth)
|
|
120
|
+
endfunction
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# $function: unittestMockOne
|
|
124
|
+
# $group: unittestMock.mds
|
|
125
|
+
# $doc: Start a function mock.
|
|
126
|
+
# $doc: To stop mocking, call the [unittestMockEnd](#var.vGroup='unittestMock.mds'&unittestmockend) function.
|
|
127
|
+
# $arg funcName: The name of the function to mock
|
|
128
|
+
# $arg mockFunc: The mock function
|
|
129
|
+
function unittestMockOne(funcName, mockFunc):
|
|
130
|
+
# Replace the function withi the mocked function
|
|
131
|
+
objectSet(unittestMockFunctions, funcName, systemGlobalGet(funcName))
|
|
132
|
+
systemGlobalSet(funcName, mockFunc)
|
|
133
|
+
endfunction
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# $function: unittestMockOneGeneric
|
|
137
|
+
# $group: unittestMock.mds
|
|
138
|
+
# $doc: Start a generic function mock.
|
|
139
|
+
# $doc: To stop mocking, call the [unittestMockEnd](#var.vGroup='unittestMock.mds'&unittestmockend) function.
|
|
140
|
+
# $arg funcName: The name of the function to mock
|
|
141
|
+
function unittestMockOneGeneric(funcName):
|
|
142
|
+
return unittestMockOne(funcName, systemPartial(unittestMockGeneric, funcName))
|
|
143
|
+
endfunction
|
|
144
|
+
|
|
145
|
+
function unittestMockGeneric(funcName, args...):
|
|
146
|
+
# Record the mocked function call
|
|
147
|
+
arrayPush(unittestMockCalls, arrayNew(funcName, args))
|
|
148
|
+
endfunction
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# $function: unittestMockEnd
|
|
152
|
+
# $group: unittestMock.mds
|
|
153
|
+
# $doc: Stop all function mocks
|
|
154
|
+
# $return: The array of mock function call tuples of the form (function name, function argument array)
|
|
155
|
+
function unittestMockEnd():
|
|
156
|
+
# Restore the original functions
|
|
157
|
+
for funcName in objectKeys(unittestMockFunctions):
|
|
158
|
+
systemGlobalSet(funcName, objectGet(unittestMockFunctions, funcName))
|
|
159
|
+
endfor
|
|
160
|
+
|
|
161
|
+
# Reset the mock state
|
|
162
|
+
mockCalls = unittestMockCalls
|
|
163
|
+
systemGlobalSet('unittestMockCalls', arrayNew())
|
|
164
|
+
systemGlobalSet('unittestMockFunctions', objectNew())
|
|
165
|
+
systemGlobalSet('unittestMockState', objectCopy(unittestMockStateDefault))
|
|
166
|
+
|
|
167
|
+
return mockCalls
|
|
168
|
+
endfunction
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
#
|
|
172
|
+
# Document functions
|
|
173
|
+
#
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
function unittestMock_documentFontSize():
|
|
177
|
+
return unittestMockDefaultFontSizePx
|
|
178
|
+
endfunction
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
function unittestMock_documentInputValue(data, args...):
|
|
182
|
+
id = arrayGet(args, 0)
|
|
183
|
+
|
|
184
|
+
# Record the mocked function call
|
|
185
|
+
arrayPush(unittestMockCalls, arrayNew('documentInputValue', args))
|
|
186
|
+
|
|
187
|
+
# Return the mocked documentInputValue response
|
|
188
|
+
return if(data != null, objectGet(data, id))
|
|
189
|
+
endfunction
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
function unittestMock_documentURL(url):
|
|
193
|
+
return url
|
|
194
|
+
endfunction
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
#
|
|
198
|
+
# Drawing functions
|
|
199
|
+
#
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
function unittestMock_drawHeight():
|
|
203
|
+
return objectGet(unittestMockState, 'drawingHeight')
|
|
204
|
+
endfunction
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
function unittestMock_drawNew(args...):
|
|
208
|
+
width = arrayGet(args, 0)
|
|
209
|
+
height = arrayGet(args, 1)
|
|
210
|
+
|
|
211
|
+
# Record the mocked function call
|
|
212
|
+
arrayPush(unittestMockCalls, arrayNew('drawNew', args))
|
|
213
|
+
|
|
214
|
+
# Update the mock state
|
|
215
|
+
objectSet(unittestMockState, 'drawingWidth', width)
|
|
216
|
+
objectSet(unittestMockState, 'drawingHeight', height)
|
|
217
|
+
endfunction
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
function unittestMock_drawTextHeight(text, width):
|
|
221
|
+
if width > 0:
|
|
222
|
+
return width / (unittestMockFontWidthRatio * stringLength(text))
|
|
223
|
+
endif
|
|
224
|
+
return objectGet(unittestMockState, 'drawingFontSizePx')
|
|
225
|
+
endfunction
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
function unittestMock_drawTextStyle(args...):
|
|
229
|
+
fontSizePx = arrayGet(args, 0)
|
|
230
|
+
|
|
231
|
+
# Record the mocked function call
|
|
232
|
+
arrayPush(unittestMockCalls, arrayNew('drawTextStyle', args))
|
|
233
|
+
|
|
234
|
+
# Update the mock state
|
|
235
|
+
objectSet(unittestMockState, 'drawingFontSizePx', if(fontSizePx != null, fontSizePx, unittestMockDefaultFontSizePx))
|
|
236
|
+
endfunction
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
function unittestMock_drawTextWidth(text, fontSizePx):
|
|
240
|
+
return unittestMockFontWidthRatio * fontSizePx * stringLength(text)
|
|
241
|
+
endfunction
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
function unittestMock_drawWidth():
|
|
245
|
+
return objectGet(unittestMockState, 'drawingWidth')
|
|
246
|
+
endfunction
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
#
|
|
250
|
+
# Local Storage functions
|
|
251
|
+
#
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
function unittestMock_localStorageClear(args...):
|
|
255
|
+
# Record the mocked function call
|
|
256
|
+
arrayPush(unittestMockCalls, arrayNew('localStorageClear', args))
|
|
257
|
+
|
|
258
|
+
# Update the mock state
|
|
259
|
+
objectSet(unittestMockState, 'localStorage', objectNew())
|
|
260
|
+
endfunction
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
function unittestMock_localStorageGet(key):
|
|
264
|
+
return objectGet(objectGet(unittestMockState, 'localStorage'), key)
|
|
265
|
+
endfunction
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
function unittestMock_localStorageRemove(args...):
|
|
269
|
+
key = arrayGet(args, 0)
|
|
270
|
+
|
|
271
|
+
# Record the mocked function call
|
|
272
|
+
arrayPush(unittestMockCalls, arrayNew('localStorageRemove', args))
|
|
273
|
+
|
|
274
|
+
# Update the mock state
|
|
275
|
+
objectDelete(objectGet(unittestMockState, 'localStorage'), key)
|
|
276
|
+
endfunction
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
function unittestMock_localStorageSet(args...):
|
|
280
|
+
key = arrayGet(args, 0)
|
|
281
|
+
value = arrayGet(args, 1)
|
|
282
|
+
|
|
283
|
+
# Record the mocked function call
|
|
284
|
+
arrayPush(unittestMockCalls, arrayNew('localStorageSet', args))
|
|
285
|
+
|
|
286
|
+
# Update the mock state
|
|
287
|
+
objectSet(objectGet(unittestMockState, 'localStorage'), key, value)
|
|
288
|
+
endfunction
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
#
|
|
292
|
+
# Markdown functions
|
|
293
|
+
#
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
function unittestMock_markdownEscape(text):
|
|
297
|
+
return regexReplace(unittestMock_markdownEscapeRegex, text, '\\$1')
|
|
298
|
+
endfunction
|
|
299
|
+
|
|
300
|
+
unittestMock_markdownEscapeRegex = regexNew('([\\\\[\\]()<>"\'*_~`#=+|-])')
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
function unittestMock_markdownHeaderId(text):
|
|
304
|
+
result = stringLower(text)
|
|
305
|
+
result = regexReplace(unittestMock_markdownHeaderId_start, result, '')
|
|
306
|
+
result = regexReplace(unittestMock_markdownHeaderId_end, result, '')
|
|
307
|
+
result = regexReplace(unittestMock_markdownHeaderId_remove, result, '')
|
|
308
|
+
return regexReplace(unittestMock_markdownHeaderId_dash, result, '-')
|
|
309
|
+
endfunction
|
|
310
|
+
|
|
311
|
+
unittestMock_markdownHeaderId_start = regexNew('^[^a-z0-9]+')
|
|
312
|
+
unittestMock_markdownHeaderId_end = regexNew('[^a-z0-9]+$')
|
|
313
|
+
unittestMock_markdownHeaderId_remove = regexNew('[\'"]')
|
|
314
|
+
unittestMock_markdownHeaderId_dash = regexNew('[^a-z0-9]+')
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
function unittestMock_markdownParse(data, args...):
|
|
318
|
+
# Record the mocked function call
|
|
319
|
+
arrayPush(unittestMockCalls, arrayNew('markdownParse', args))
|
|
320
|
+
|
|
321
|
+
# Return the mocked markdownParse response
|
|
322
|
+
return if(data != null, arrayShift(data))
|
|
323
|
+
endfunction
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
function unittestMock_markdownTitle(data, args...):
|
|
327
|
+
# Record the mocked function call
|
|
328
|
+
arrayPush(unittestMockCalls, arrayNew('markdownTitle', args))
|
|
329
|
+
|
|
330
|
+
# Return the mocked markdownTitle response
|
|
331
|
+
return if(data != null, arrayShift(data))
|
|
332
|
+
endfunction
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
#
|
|
336
|
+
# Schema functions
|
|
337
|
+
#
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
function unittestMock_schemaElements(types, typeName):
|
|
341
|
+
userType = objectGet(types, typeName)
|
|
342
|
+
userTypeKey = arrayGet(objectKeys(userType), 0)
|
|
343
|
+
if userTypeKey == 'struct' && objectGet(objectGet(userType, 'struct'), 'union'):
|
|
344
|
+
userTypeKey = 'union'
|
|
345
|
+
endif
|
|
346
|
+
return arrayNew( \
|
|
347
|
+
arrayNew( \
|
|
348
|
+
objectNew('html', 'h1', 'elem', objectNew('text', userTypeKey + ' ' + typeName)) \
|
|
349
|
+
) \
|
|
350
|
+
)
|
|
351
|
+
endfunction
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
#
|
|
355
|
+
# Session Storage functions
|
|
356
|
+
#
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
function unittestMock_sessionStorageClear(args...):
|
|
360
|
+
# Record the mocked function call
|
|
361
|
+
arrayPush(unittestMockCalls, arrayNew('sessionStorageClear', args))
|
|
362
|
+
|
|
363
|
+
# Update the mock state
|
|
364
|
+
objectSet(unittestMockState, 'sessionStorage', objectNew())
|
|
365
|
+
endfunction
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
function unittestMock_sessionStorageGet(key):
|
|
369
|
+
return objectGet(objectGet(unittestMockState, 'sessionStorage'), key)
|
|
370
|
+
endfunction
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
function unittestMock_sessionStorageRemove(args...):
|
|
374
|
+
key = arrayGet(args, 0)
|
|
375
|
+
|
|
376
|
+
# Record the mocked function call
|
|
377
|
+
arrayPush(unittestMockCalls, arrayNew('sessionStorageRemove', args))
|
|
378
|
+
|
|
379
|
+
# Update the mock state
|
|
380
|
+
objectDelete(objectGet(unittestMockState, 'sessionStorage'), key)
|
|
381
|
+
endfunction
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
function unittestMock_sessionStorageSet(args...):
|
|
385
|
+
key = arrayGet(args, 0)
|
|
386
|
+
value = arrayGet(args, 1)
|
|
387
|
+
|
|
388
|
+
# Record the mocked function call
|
|
389
|
+
arrayPush(unittestMockCalls, arrayNew('sessionStorageSet', args))
|
|
390
|
+
|
|
391
|
+
# Update the mock state
|
|
392
|
+
objectSet(objectGet(unittestMockState, 'sessionStorage'), key, value)
|
|
393
|
+
endfunction
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
#
|
|
397
|
+
# System functions
|
|
398
|
+
#
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
function unittestMock_systemFetch(data, args...):
|
|
402
|
+
url = arrayGet(args, 0)
|
|
403
|
+
|
|
404
|
+
# Record the mocked function call
|
|
405
|
+
arrayPush(unittestMockCalls, arrayNew('systemFetch', args))
|
|
406
|
+
|
|
407
|
+
# Array of URLs?
|
|
408
|
+
urlType = systemType(url)
|
|
409
|
+
if urlType == 'array':
|
|
410
|
+
result = arrayNew()
|
|
411
|
+
for urlItem in url:
|
|
412
|
+
urlActual = if(systemType(urlItem) == 'object', objectGet(urlItem, 'url'), urlItem)
|
|
413
|
+
arrayPush(result, if(data != null, objectGet(data, urlActual)))
|
|
414
|
+
endfor
|
|
415
|
+
return result
|
|
416
|
+
endif
|
|
417
|
+
|
|
418
|
+
# Return the mocked systemFetch response
|
|
419
|
+
urlActual = if(urlType == 'object', objectGet(url, 'url'), url)
|
|
420
|
+
return if(data != null, objectGet(data, urlActual))
|
|
421
|
+
endfunction
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
#
|
|
425
|
+
# URL functions
|
|
426
|
+
#
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
function unittestMock_urlObjectCreate(data, contentType):
|
|
430
|
+
return 'blob:' + urlEncode(contentType) + '-' + urlEncode(if(stringLength(data) < 20, data, stringSlice(data, 0, 20)))
|
|
431
|
+
endfunction
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
#
|
|
435
|
+
# Window functions
|
|
436
|
+
#
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
function unittestMock_windowClipboardRead():
|
|
440
|
+
return objectGet(unittestMockState, 'windowClipboard')
|
|
441
|
+
endfunction
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
function unittestMock_windowClipboardWrite(args...):
|
|
445
|
+
text = arrayGet(args, 0)
|
|
446
|
+
|
|
447
|
+
# Record the mocked function call
|
|
448
|
+
arrayPush(unittestMockCalls, arrayNew('windowClipboardWrite', args))
|
|
449
|
+
|
|
450
|
+
# Update the mock state
|
|
451
|
+
objectSet(unittestMockState, 'windowClipboard', text)
|
|
452
|
+
endfunction
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
function unittestMock_windowHeight():
|
|
456
|
+
return unittestMockWindowHeight
|
|
457
|
+
endfunction
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
function unittestMock_windowWidth():
|
|
461
|
+
return unittestMockWindowWidth
|
|
462
|
+
endfunction
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "bare-script",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"description": "BareScript; a lightweight scripting and expression language",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"expression",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"c8": "~10.1",
|
|
34
|
-
"eslint": "~9.
|
|
34
|
+
"eslint": "~9.19",
|
|
35
35
|
"jsdoc": "~4.0"
|
|
36
36
|
}
|
|
37
37
|
}
|