| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | import { describe, it, expect } from "vitest"; | 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { transform, CloverQuestionExtensions } from "./mod.ts"; | 2 | import { CloverQuestionExtensions, transform } from "./mod.ts"; |
| 3 | | 3 | |
| 4 | const cloverExtensions: CloverQuestionExtensions = { | 4 | const cloverExtensions: CloverQuestionExtensions = { |
| 5 | question: "q-block", | 5 | question: "q-block", |
| ... | @@ -32,9 +32,9 @@ describe("clover extensions", () => { | ... | @@ -32,9 +32,9 @@ describe("clover extensions", () => { |
| 32 | }); | 32 | }); |
| 33 | expect(result.success).toBe(true); | 33 | expect(result.success).toBe(true); |
| 34 | if (result.success) { | 34 | if (result.success) { |
| 35 | expect(result.text).toContain("<br />"); | 35 | expect(result.text).toContain( |
| 36 | expect(result.text).toContain("<q-block>first question</q-block>"); | 36 | "<q-block>first question<br>second question</q-block>", |
| 37 | expect(result.text).toContain("<q-block>second question</q-block>"); | 37 | ); |
| 38 | } | 38 | } |
| 39 | }); | 39 | }); |
| 40 | | 40 | |
| ... | @@ -73,7 +73,7 @@ describe("clover extensions", () => { | ... | @@ -73,7 +73,7 @@ describe("clover extensions", () => { |
| 73 | expect(result.success).toBe(true); | 73 | expect(result.success).toBe(true); |
| 74 | if (result.success) { | 74 | if (result.success) { |
| 75 | expect(result.text).toContain( | 75 | expect(result.text).toContain( |
| 76 | '<custom-element attr="value">content</custom-element>' | 76 | '<custom-element attr="value">content</custom-element>', |
| 77 | ); | 77 | ); |
| 78 | } | 78 | } |
| 79 | }); | 79 | }); |
| ... | @@ -102,7 +102,7 @@ describe("clover extensions", () => { | ... | @@ -102,7 +102,7 @@ describe("clover extensions", () => { |
| 102 | expect(result.success).toBe(true); | 102 | expect(result.success).toBe(true); |
| 103 | if (result.success) { | 103 | if (result.success) { |
| 104 | expect(result.text).toContain( | 104 | expect(result.text).toContain( |
| 105 | "<artifact-ref>its-snowing</artifact-ref>" | 105 | "<artifact-ref>its-snowing</artifact-ref>", |
| 106 | ); | 106 | ); |
| 107 | } | 107 | } |
| 108 | }); | 108 | }); |
| ... | @@ -117,7 +117,7 @@ describe("clover extensions", () => { | ... | @@ -117,7 +117,7 @@ describe("clover extensions", () => { |
| 117 | if (result.success) { | 117 | if (result.success) { |
| 118 | expect(result.text).toContain("<artifact-ref>first-one</artifact-ref>"); | 118 | expect(result.text).toContain("<artifact-ref>first-one</artifact-ref>"); |
| 119 | expect(result.text).toContain( | 119 | expect(result.text).toContain( |
| 120 | "<artifact-ref>second-one</artifact-ref>" | 120 | "<artifact-ref>second-one</artifact-ref>", |
| 121 | ); | 121 | ); |
| 122 | } | 122 | } |
| 123 | }); | 123 | }); |
| ... | @@ -131,7 +131,7 @@ describe("clover extensions", () => { | ... | @@ -131,7 +131,7 @@ describe("clover extensions", () => { |
| 131 | expect(result.success).toBe(true); | 131 | expect(result.success).toBe(true); |
| 132 | if (result.success) { | 132 | if (result.success) { |
| 133 | expect(result.text).toContain( | 133 | expect(result.text).toContain( |
| 134 | "<artifact-ref>valid-slug123</artifact-ref>" | 134 | "<artifact-ref>valid-slug123</artifact-ref>", |
| 135 | ); | 135 | ); |
| 136 | expect(result.text).toContain("@INVALID"); | 136 | expect(result.text).toContain("@INVALID"); |
| 137 | expect(result.text).not.toContain("<artifact-ref>INVALID"); | 137 | expect(result.text).not.toContain("<artifact-ref>INVALID"); |
| ... | @@ -161,7 +161,7 @@ describe("clover extensions", () => { | ... | @@ -161,7 +161,7 @@ describe("clover extensions", () => { |
| 161 | expect(result.success).toBe(true); | 161 | expect(result.success).toBe(true); |
| 162 | if (result.success) { | 162 | if (result.success) { |
| 163 | expect(result.text).toContain( | 163 | expect(result.text).toContain( |
| 164 | "<question-ref>2602142011</question-ref>" | 164 | "<question-ref>2602142011</question-ref>", |
| 165 | ); | 165 | ); |
| 166 | } | 166 | } |
| 167 | }); | 167 | }); |
| ... | @@ -175,7 +175,7 @@ describe("clover extensions", () => { | ... | @@ -175,7 +175,7 @@ describe("clover extensions", () => { |
| 175 | expect(result.success).toBe(true); | 175 | expect(result.success).toBe(true); |
| 176 | if (result.success) { | 176 | if (result.success) { |
| 177 | expect(result.text).toContain( | 177 | expect(result.text).toContain( |
| 178 | "<question-ref>260214201112</question-ref>" | 178 | "<question-ref>260214201112</question-ref>", |
| 179 | ); | 179 | ); |
| 180 | } | 180 | } |
| 181 | }); | 181 | }); |
| ... | @@ -205,31 +205,31 @@ describe("clover extensions", () => { | ... | @@ -205,31 +205,31 @@ describe("clover extensions", () => { |
| 205 | expect(result.success).toBe(true); | 205 | expect(result.success).toBe(true); |
| 206 | if (result.success) { | 206 | if (result.success) { |
| 207 | expect(result.text).toContain( | 207 | expect(result.text).toContain( |
| 208 | "<question-ref>2602142011</question-ref>" | 208 | "<question-ref>2602142011</question-ref>", |
| 209 | ); | 209 | ); |
| 210 | expect(result.text).toContain( | 210 | expect(result.text).toContain( |
| 211 | "<question-ref>2602142012</question-ref>" | 211 | "<question-ref>2602142012</question-ref>", |
| 212 | ); | 212 | ); |
| 213 | } | 213 | } |
| 214 | }); | 214 | }); |
| 215 | }); | 215 | }); |
| 216 | | 216 | |
| 217 | describe("labelled redactions", () => { | 217 | describe("labelled redactions", () => { |
| 218 | it("transforms ##label## to redaction element", () => { | 218 | it("transforms #label# to redaction element", () => { |
| 219 | const result = transform({ | 219 | const result = transform({ |
| 220 | source: "the ##secret name## is hidden", | 220 | source: "the #name# is hidden", |
| 221 | markdownOnly: true, | 221 | markdownOnly: true, |
| 222 | cloverExtensions, | 222 | cloverExtensions, |
| 223 | }); | 223 | }); |
| 224 | expect(result.success).toBe(true); | 224 | expect(result.success).toBe(true); |
| 225 | if (result.success) { | 225 | if (result.success) { |
| 226 | expect(result.text).toContain("<redacted>secret name</redacted>"); | 226 | expect(result.text).toContain("<redacted>name</redacted>"); |
| 227 | } | 227 | } |
| 228 | }); | 228 | }); |
| 229 | | 229 | |
| 230 | it("handles hyphens and underscores in labels", () => { | 230 | it("handles hyphens and underscores in labels", () => { |
| 231 | const result = transform({ | 231 | const result = transform({ |
| 232 | source: "##my-secret_label##", | 232 | source: "#my-secret_label#", |
| 233 | markdownOnly: true, | 233 | markdownOnly: true, |
| 234 | cloverExtensions, | 234 | cloverExtensions, |
| 235 | }); | 235 | }); |
| ... | @@ -241,21 +241,21 @@ describe("clover extensions", () => { | ... | @@ -241,21 +241,21 @@ describe("clover extensions", () => { |
| 241 | | 241 | |
| 242 | it("does not match empty labels", () => { | 242 | it("does not match empty labels", () => { |
| 243 | const result = transform({ | 243 | const result = transform({ |
| 244 | source: "text #### more", | 244 | source: "text ## ### #### more", |
| 245 | markdownOnly: true, | 245 | markdownOnly: true, |
| 246 | cloverExtensions, | 246 | cloverExtensions, |
| 247 | }); | 247 | }); |
| 248 | expect(result.success).toBe(true); | 248 | expect(result.success).toBe(true); |
| 249 | if (result.success) { | 249 | if (result.success) { |
| 250 | expect(result.text).not.toContain("<redacted></redacted>"); | 250 | expect(result.text).not.toContain("<redacted>"); |
| 251 | // #### in the middle of text stays as-is | 251 | // ## in the middle of text stays as-is |
| 252 | expect(result.text).toContain("####"); | 252 | expect(result.text).toContain("##"); |
| 253 | } | 253 | } |
| 254 | }); | 254 | }); |
| 255 | | 255 | |
| 256 | it("handles multiple redactions", () => { | 256 | it("handles multiple redactions", () => { |
| 257 | const result = transform({ | 257 | const result = transform({ |
| 258 | source: "##first## and ##second##", | 258 | source: "#first# and #second#", |
| 259 | markdownOnly: true, | 259 | markdownOnly: true, |
| 260 | cloverExtensions, | 260 | cloverExtensions, |
| 261 | }); | 261 | }); |
| ... | @@ -273,7 +273,7 @@ describe("clover extensions", () => { | ... | @@ -273,7 +273,7 @@ describe("clover extensions", () => { |
| 273 | source: `q: what is @some-artifact about? | 273 | source: `q: what is @some-artifact about? |
| 274 | q: also see #2602142011 | 274 | q: also see #2602142011 |
| 275 | | 275 | |
| 276 | The ##secret## is revealed. | 276 | The #secret# is revealed. |
| 277 | | 277 | |
| 278 | @html <hr class="divider" />`, | 278 | @html <hr class="divider" />`, |
| 279 | markdownOnly: true, | 279 | markdownOnly: true, |
| ... | @@ -281,12 +281,12 @@ The ##secret## is revealed. | ... | @@ -281,12 +281,12 @@ The ##secret## is revealed. |
| 281 | }); | 281 | }); |
| 282 | expect(result.success).toBe(true); | 282 | expect(result.success).toBe(true); |
| 283 | if (result.success) { | 283 | if (result.success) { |
| 284 | expect(result.text).toContain("<q-block>"); | 284 | expect(result.text).toBe( |
| 285 | expect(result.text).toContain("<artifact-ref>some-artifact</artifact-ref>"); | 285 | `<q-block>what is <artifact-ref>some-artifact</artifact-ref> about?<br>also see <question-ref>2602142011</question-ref></q-block> |
| 286 | expect(result.text).toContain("<question-ref>2602142011</question-ref>"); | 286 | <p>The <redacted>secret</redacted> is revealed.</p> |
| 287 | expect(result.text).toContain("<redacted>secret</redacted>"); | 287 | <hr class="divider" /> |
| 288 | expect(result.text).toContain('<hr class="divider" />'); | 288 | `, |
| 289 | expect(result.text).toContain("<br />"); // between consecutive q: lines | 289 | ); |
| 290 | } | 290 | } |
| 291 | }); | 291 | }); |
| 292 | | 292 | |
| ... | @@ -306,7 +306,8 @@ The ##secret## is revealed. | ... | @@ -306,7 +306,8 @@ The ##secret## is revealed. |
| 306 | describe("without cloverExtensions", () => { | 306 | describe("without cloverExtensions", () => { |
| 307 | it("does not parse clover syntax when extensions not provided", () => { | 307 | it("does not parse clover syntax when extensions not provided", () => { |
| 308 | const result = transform({ | 308 | const result = transform({ |
| 309 | source: "q: not a question\n@not-artifact\n#2602142011\n##not-redacted##", | 309 | source: |
| | 310 | "q: not a question\n@not-artifact\n#2602142011\n##not-redacted##", |
| 310 | markdownOnly: true, | 311 | markdownOnly: true, |
| 311 | }); | 312 | }); |
| 312 | expect(result.success).toBe(true); | 313 | expect(result.success).toBe(true); |
| ... | @@ -320,3 +321,23 @@ The ##secret## is revealed. | ... | @@ -320,3 +321,23 @@ The ##secret## is revealed. |
| 320 | }); | 321 | }); |
| 321 | }); | 322 | }); |
| 322 | }); | 323 | }); |
| | 324 | |
| | 325 | it("sample cases", () => { |
| | 326 | expect( |
| | 327 | transform({ |
| | 328 | source: `q: how is/was your valentine's day? |
| | 329 | |
| | 330 | it was overall good but i don't understand why i'm loved as much as i am. but i appreciate her in every way. also every time i look away, my [frieren collection](/file/q+a/frieren.jpeg) is slowly growing. |
| | 331 | |
| | 332 | @html <p style="color:#81D8D0;padding-left:30px">[clo] is rly cutee and nice to me so i love her alot and pat her head a lot and i miss [clo] meow hug her shes rly cool and does rly cool things and shes cute and likes frieren and meow</p> |
| | 333 | |
| | 334 | oh oops i left my answering machine out.`, |
| | 335 | markdownOnly: true, |
| | 336 | cloverExtensions, |
| | 337 | }).text, |
| | 338 | ).toBe(`<q-block>how is/was your valentine’s day?</q-block> |
| | 339 | <p>it was overall good but i don’t understand why i’m loved as much as i am. but i appreciate her in every way. also every time i look away, my <a href="/file/q+a/frieren.jpeg">frieren collection</a> is slowly growing.</p> |
| | 340 | <p style="color:#81D8D0;padding-left:30px">[clo] is rly cutee and nice to me so i love her alot and pat her head a lot and i miss [clo] meow hug her shes rly cool and does rly cool things and shes cute and likes frieren and meow</p> |
| | 341 | <p>oh oops i left my answering machine out.</p> |
| | 342 | `); |
| | 343 | }); |