Skip to content

Commit

Permalink
... actually update the processor validation
Browse files Browse the repository at this point in the history
  • Loading branch information
brekk committed Jan 4, 2024
1 parent b61bbc3 commit 1c4e784
Show file tree
Hide file tree
Showing 7 changed files with 539 additions and 74 deletions.
34 changes: 27 additions & 7 deletions apps/docs/dr-generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@
"filename": "packages/doctor-general/processor.js",
"comments": [
{
"start": 25,
"end": 43,
"start": 34,
"end": 54,
"summary": "Check to see if a given function is both curried and matches an expected arity.\nSpecific arguments can be applied or the same argument can be applied multiple times.\nReturn values are eschewed entirely and errors will be silently swallowed.",
"links": [],
"fileGroup": "",
"addTo": "",
"structure": {
"name": "isCurriedFunctionWithArgs",
"example": "```js test=true\nimport { curry } from 'ramda'\n// drgen-import-above\nconst args = [1,2,3,4]\nconst div = curry((a, b) => b / a)\nconst fourArr = curry((a, b, c, d) => [a,b,c,d])\nconst isCurriedWithArity = isCurriedFunctionWithArgs(args)\nexpect(isCurriedWithArity(2, div)).toBeTruthy()\nexpect(isCurriedWithArity(4, fourArr)).toBeTruthy()\nexpect(isCurriedWithArity(3, fourArr)).toBeFalsy()\nexpect(isCurriedWithArity(3, \"???\")).toBeFalsy()\n```"
"example": "```js test=true\nimport { curry } from 'ramda'\n// drgen-import-above\nconst args = [1,2,3,4]\nconst div = curry((a, b) => b / a)\nconst fourArr = curry((a, b, c, d) => [a,b,c,d])\nconst isCurriedWithArity = isCurriedFunctionWithArgs(args)\nexpect(isCurriedWithArity(2, div)).toBeTruthy()\nexpect(isCurriedWithArity(4, fourArr)).toBeTruthy()\nexpect(isCurriedWithArity(3, fourArr)).toBeFalsy()\nexpect(isCurriedWithArity(3, \"???\")).toBeFalsy()\nexpect(isCurriedWithArity(3, (a, b, c) => c)).toBeFalsy()\nexpect(isCurriedFunctionWithArgs(1, 4, fourArr)).toBeTruthy()\n```"
},
"keywords": [
"@example",
Expand All @@ -335,16 +335,36 @@
"package": "doctor-general"
},
{
"start": 95,
"end": 121,
"summary": "@name validate",
"start": 120,
"end": 237,
"summary": "Apply tests to a given processor in order to assess its correctness.",
"links": [],
"fileGroup": "",
"addTo": "",
"structure": {
"name": "interrogate",
"exported": true,
"example": "```js test=true\n// import { curry } from 'ramda'\n// drgen-import-above\nconst myCoolProcessor = {\n output: () => {},\n group: '',\n process: () => {},\n postProcess: curry((a, b, c) => c),\n renderer: curry((a, b) => b),\n}\nexpect(interrogate({})).toEqual({\n additionalFieldCheck: {},\n additionalFields: [],\n meetsOptionalRequirements: false,\n meetsRequirements: false,\n incorrectFields: [\n 'output',\n 'group',\n 'process',\n 'postProcess',\n 'renderer',\n 'postRender'\n ],\n checked: {\n optional: { postRender: false },\n required: {\n group: false,\n output: false,\n postProcess: false,\n process: false,\n renderer: false\n }\n }\n})\nexpect(interrogate(myCoolProcessor)).toEqual({\n additionalFieldCheck: {},\n additionalFields: [],\n meetsOptionalRequirements: false,\n meetsRequirements: true,\n incorrectFields: ['postRender'],\n checked: {\n optional: { postRender: false },\n required: {\n group: true,\n output: true,\n postProcess: true,\n process: true,\n renderer: true\n }\n }\n})\nexpect(interrogate(Object.assign({},\n myCoolProcessor,\n { postRender: curry((a, b) => b) }\n))).toEqual({\n additionalFieldCheck: { postRender: true },\n additionalFields: [ 'postRender' ],\n meetsOptionalRequirements: true,\n meetsRequirements: true,\n incorrectFields: [],\n checked: {\n optional: { postRender: true },\n required: {\n group: true,\n output: true,\n postProcess: true,\n process: true,\n renderer: true\n }\n }\n})\nexpect(interrogate(Object.assign({},\n myCoolProcessor,\n { unsupportedFunction: curry((a, b) => b) }\n))).toEqual({\n additionalFieldCheck: { unsupportedFunction: false },\n additionalFields: ['unsupportedFunction'],\n meetsOptionalRequirements: false,\n meetsRequirements: true,\n checked: {\n optional: { postRender: false },\n required: {\n group: true,\n output: true,\n postProcess: true,\n process: true,\n renderer: true\n }\n },\n incorrectFields: ['postRender']\n})\nexpect(interrogate(Object.assign({},\n myCoolProcessor,\n { renderer: function uncurriedBinary(a, b) { return b } }\n))).toEqual({\n additionalFieldCheck: {},\n additionalFields: [],\n meetsOptionalRequirements: false,\n meetsRequirements: false,\n incorrectFields: ['renderer', 'postRender'],\n checked: {\n optional: { postRender: false },\n required: {\n group: true,\n output: true,\n postProcess: true,\n process: true,\n renderer: false,\n }\n }\n})\n```"
},
"keywords": [
"@example",
"@exported",
"@name"
],
"filename": "packages/doctor-general/processor.js",
"package": "doctor-general"
},
{
"start": 276,
"end": 308,
"summary": "Validate a given processor is correct.\nIf you want to see _why_ it is incorrect, use `interrogate` instead.",
"links": [],
"fileGroup": "",
"addTo": "",
"structure": {
"name": "validate",
"exported": true,
"example": "```js test=true\n// import { curry } from 'ramda'\n// drgen-import-above\nconst myCoolProcessor = {\n output: () => {},\n group: '',\n process: () => {},\n postProcess: curry((a, b, c) => c),\n renderer: curry((a, b) => b),\n}\n\nexpect(validate({})).toBeFalsy()\nexpect(validate(myCoolProcessor)).toBeTruthy()\nexpect(validate({\n ...myCoolProcessor,\n postRender: curry((a, b) => b)\n})).toBeTruthy()\nexpect(validate({\n ...myCoolProcessor,\n unsupportedFunction: curry((a, b) => b)\n})).toBeFalsy()\n```"
"example": "```js test=true\n// import { curry } from 'ramda'\n// drgen-import-above\nconst myCoolProcessor = {\n output: () => {},\n group: '',\n process: () => {},\n postProcess: curry((a, b, c) => c),\n renderer: curry((a, b) => b),\n}\n\nexpect(validate({})).toBeFalsy()\nexpect(validate(myCoolProcessor)).toBeTruthy()\nexpect(validate(Object.assign({},\n myCoolProcessor,\n { postRender: curry((a, b) => b) }\n))).toBeTruthy()\nexpect(validate(Object.assign({},\n myCoolProcessor,\n { unsupportedFunction: curry((a, b) => b) }\n))).toBeFalsy()\nexpect(validate(Object.assign({},\n myCoolProcessor,\n { renderer: function uncurriedBinary(a, b) { return b } }\n))).toBeFalsy()\n```"
},
"keywords": [
"@example",
Expand Down
147 changes: 137 additions & 10 deletions apps/docs/pages/doctor-general/processor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,138 @@ expect(isCurriedWithArity(2, div)).toBeTruthy()
expect(isCurriedWithArity(4, fourArr)).toBeTruthy()
expect(isCurriedWithArity(3, fourArr)).toBeFalsy()
expect(isCurriedWithArity(3, "???")).toBeFalsy()
expect(isCurriedWithArity(3, (a, b, c) => c)).toBeFalsy()
expect(isCurriedFunctionWithArgs(1, 4, fourArr)).toBeTruthy()
```

## interrogate

Apply tests to a given processor in order to assess its correctness.

### Usage
```js test=true
import { isCurriedFunctionWithArgs, interrogate, validate } from 'doctor-general'

// import { curry } from 'ramda'

const myCoolProcessor = {
output: () => {},
group: '',
process: () => {},
postProcess: curry((a, b, c) => c),
renderer: curry((a, b) => b),
}
expect(interrogate({})).toEqual({
additionalFieldCheck: {},
additionalFields: [],
meetsOptionalRequirements: false,
meetsRequirements: false,
incorrectFields: [
'output',
'group',
'process',
'postProcess',
'renderer',
'postRender'
],
checked: {
optional: { postRender: false },
required: {
group: false,
output: false,
postProcess: false,
process: false,
renderer: false
}
}
})
expect(interrogate(myCoolProcessor)).toEqual({
additionalFieldCheck: {},
additionalFields: [],
meetsOptionalRequirements: false,
meetsRequirements: true,
incorrectFields: ['postRender'],
checked: {
optional: { postRender: false },
required: {
group: true,
output: true,
postProcess: true,
process: true,
renderer: true
}
}
})
expect(interrogate(Object.assign({},
myCoolProcessor,
{ postRender: curry((a, b) => b) }
))).toEqual({
additionalFieldCheck: { postRender: true },
additionalFields: [ 'postRender' ],
meetsOptionalRequirements: true,
meetsRequirements: true,
incorrectFields: [],
checked: {
optional: { postRender: true },
required: {
group: true,
output: true,
postProcess: true,
process: true,
renderer: true
}
}
})
expect(interrogate(Object.assign({},
myCoolProcessor,
{ unsupportedFunction: curry((a, b) => b) }
))).toEqual({
additionalFieldCheck: { unsupportedFunction: false },
additionalFields: ['unsupportedFunction'],
meetsOptionalRequirements: false,
meetsRequirements: true,
checked: {
optional: { postRender: false },
required: {
group: true,
output: true,
postProcess: true,
process: true,
renderer: true
}
},
incorrectFields: ['postRender']
})
expect(interrogate(Object.assign({},
myCoolProcessor,
{ renderer: function uncurriedBinary(a, b) { return b } }
))).toEqual({
additionalFieldCheck: {},
additionalFields: [],
meetsOptionalRequirements: false,
meetsRequirements: false,
incorrectFields: ['renderer', 'postRender'],
checked: {
optional: { postRender: false },
required: {
group: true,
output: true,
postProcess: true,
process: true,
renderer: false,
}
}
})
```

## validate

@name validate
Validate a given processor is correct.
If you want to see _why_ it is incorrect, use `interrogate` instead.

### Usage
```js test=true
import { validate, isCurriedFunctionWithArgs } from 'doctor-general'
import { isCurriedFunctionWithArgs, interrogate, validate } from 'doctor-general'

// import { curry } from 'ramda'

Expand All @@ -42,12 +165,16 @@ const myCoolProcessor = {

expect(validate({})).toBeFalsy()
expect(validate(myCoolProcessor)).toBeTruthy()
expect(validate({
...myCoolProcessor,
postRender: curry((a, b) => b)
})).toBeTruthy()
expect(validate({
...myCoolProcessor,
unsupportedFunction: curry((a, b) => b)
})).toBeFalsy()
expect(validate(Object.assign({},
myCoolProcessor,
{ postRender: curry((a, b) => b) }
))).toBeTruthy()
expect(validate(Object.assign({},
myCoolProcessor,
{ unsupportedFunction: curry((a, b) => b) }
))).toBeFalsy()
expect(validate(Object.assign({},
myCoolProcessor,
{ renderer: function uncurriedBinary(a, b) { return b } }
))).toBeFalsy()
```
2 changes: 1 addition & 1 deletion apps/docs/pages/kiddo/kiddo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Add an `ora` indicator to a Future

### Usage
```js test=true
import { signal, exec } from 'kiddo'
import { signal } from 'kiddo'

import { pipe, map } from 'ramda'
import { readFile } from 'file-system'
Expand Down
1 change: 1 addition & 0 deletions packages/doctor-general/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports[`default export 1`] = `
"stats": [Function],
"string": [Function],
"text": [Function],
"validate": [Function],
"verbose": [Function],
},
"matchLinks": [Function],
Expand Down
Loading

0 comments on commit 1c4e784

Please sign in to comment.