mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 08:07:30 +00:00
Start test suite
This commit is contained in:
parent
5024dc92af
commit
70348e1934
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,3 +1,10 @@
|
|||||||
|
# Code stuff
|
||||||
node_modules
|
node_modules
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
# Database stuff
|
||||||
db/**/*.db*
|
db/**/*.db*
|
||||||
|
|
||||||
|
# Test stuff
|
||||||
|
/coverage
|
||||||
|
/.nyc_output
|
||||||
|
2565
package-lock.json
generated
2565
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cd src/site && node server.js"
|
"start": "cd src/site && node server.js",
|
||||||
|
"test": "tap"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
@ -23,5 +24,8 @@
|
|||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@deadcanaries/granax": "^3.2.5"
|
"@deadcanaries/granax": "^3.2.5"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"tap": "^14.10.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
const constants = require("../constants")
|
const constants = require("../constants")
|
||||||
const {Parser} = require("./parser/parser")
|
|
||||||
|
|
||||||
function tryMatch(text, against, callback) {
|
function tryMatch(text, against, callback) {
|
||||||
let matched = text.match(against)
|
let matched = text.match(against)
|
||||||
@ -28,6 +27,7 @@ function partsUsername(parts) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
function partsHashtag(parts) {
|
function partsHashtag(parts) {
|
||||||
@ -41,6 +41,7 @@ function partsHashtag(parts) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
function structure(text) {
|
function structure(text) {
|
||||||
@ -51,3 +52,5 @@ function structure(text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.structure = structure
|
module.exports.structure = structure
|
||||||
|
module.exports.partsUsername = partsUsername
|
||||||
|
module.exports.partsHashtag = partsHashtag
|
||||||
|
122
test/structuretext.js
Normal file
122
test/structuretext.js
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
const tap = require("tap")
|
||||||
|
const {structure, partsHashtag, partsUsername} = require("../src/lib/utils/structuretext.js")
|
||||||
|
|
||||||
|
// lone test hashtag
|
||||||
|
tap.same(
|
||||||
|
partsHashtag([
|
||||||
|
{type: "user", text: "@person"},
|
||||||
|
{type: "text", text: " #epic"}
|
||||||
|
]),
|
||||||
|
[
|
||||||
|
{type: "user", text: "@person"},
|
||||||
|
{type: "text", text: " "},
|
||||||
|
{type: "hashtag", text: "#epic", hashtag: "epic"},
|
||||||
|
{type: "text", text: ""}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
// lone test username
|
||||||
|
tap.same(
|
||||||
|
partsUsername([
|
||||||
|
{type: "hashtag", text: "#drawing", hashtag: "drawing"},
|
||||||
|
{type: "text", text: " with @person"}
|
||||||
|
]),
|
||||||
|
[
|
||||||
|
{type: "hashtag", text: "#drawing", hashtag: "drawing"},
|
||||||
|
{type: "text", text: " with "},
|
||||||
|
{type: "user", text: "@person", user: "person"},
|
||||||
|
{type: "text", text: ""}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
// plain text
|
||||||
|
tap.same(
|
||||||
|
structure("hello world"),
|
||||||
|
[
|
||||||
|
{type: "text", text: "hello world"}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
// username
|
||||||
|
tap.same(
|
||||||
|
structure("hello @person world"),
|
||||||
|
[
|
||||||
|
{type: "text", text: "hello "},
|
||||||
|
{type: "user", text: "@person", user: "person"},
|
||||||
|
{type: "text", text: " world"}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
// username at start
|
||||||
|
tap.same(
|
||||||
|
structure("@person hello"),
|
||||||
|
[
|
||||||
|
{type: "text", text: ""},
|
||||||
|
{type: "user", text: "@person", user: "person"},
|
||||||
|
{type: "text", text: " hello"}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
// username at end
|
||||||
|
tap.same(
|
||||||
|
structure("hello @person"),
|
||||||
|
[
|
||||||
|
{type: "text", text: "hello "},
|
||||||
|
{type: "user", text: "@person", user: "person"},
|
||||||
|
{type: "text", text: ""},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
// multiple usernames
|
||||||
|
tap.same(
|
||||||
|
structure("hello @person1 @person2"),
|
||||||
|
[
|
||||||
|
{type: "text", text: "hello "},
|
||||||
|
{type: "user", text: "@person1", user: "person1"},
|
||||||
|
{type: "text", text: " "},
|
||||||
|
{type: "user", text: "@person2", user: "person2"},
|
||||||
|
{type: "text", text: ""}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
// hashtag
|
||||||
|
tap.same(
|
||||||
|
structure("what a #beautiful day"),
|
||||||
|
[
|
||||||
|
{type: "text", text: "what a "},
|
||||||
|
{type: "hashtag", text: "#beautiful", hashtag: "beautiful"},
|
||||||
|
{type: "text", text: " day"}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
// mixed
|
||||||
|
tap.same(
|
||||||
|
structure("@person what a #beautiful #day in @city"),
|
||||||
|
[
|
||||||
|
{type: "text", text: ""},
|
||||||
|
{type: "user", text: "@person", user: "person"},
|
||||||
|
{type: "text", text: " what a "},
|
||||||
|
{type: "hashtag", text: "#beautiful", hashtag: "beautiful"},
|
||||||
|
{type: "text", text: " "},
|
||||||
|
{type: "hashtag", text: "#day", hashtag: "day"},
|
||||||
|
{type: "text", text: " in "},
|
||||||
|
{type: "user", text: "@city", user: "city"},
|
||||||
|
{type: "text", text: ""}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
// special characters
|
||||||
|
tap.same(
|
||||||
|
structure("#goodmorning! @city.planner, #parks\nare awesome"),
|
||||||
|
[
|
||||||
|
{type: "text", text: ""},
|
||||||
|
{type: "hashtag", text: "#goodmorning", hashtag: "goodmorning"},
|
||||||
|
{type: "text", text: "! "},
|
||||||
|
{type: "user", text: "@city.planner", user: "city.planner"},
|
||||||
|
{type: "text", text: ", "},
|
||||||
|
{type: "hashtag", text: "#parks", hashtag: "parks"},
|
||||||
|
{type: "text", text: "\nare awesome"}
|
||||||
|
]
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user