| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | | import { describe, it, expect } from "vitest"; |
| 2 | | import { transform, CloverQuestionExtensions } from "./mod.ts"; |
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { CloverQuestionExtensions, transform } from "./mod.ts"; |
| 3 | 3 | |
| 4 | 4 | const cloverExtensions: CloverQuestionExtensions = { |
| 5 | 5 | question: "q-block", |
| ... | ... | @@ -32,9 +32,9 @@ describe("clover extensions", () => { |
| 32 | 32 | }); |
| 33 | 33 | expect(result.success).toBe(true); |
| 34 | 34 | if (result.success) { |
| 35 | | expect(result.text).toContain("<br />"); |
| 36 | | expect(result.text).toContain("<q-block>first question</q-block>"); |
| 37 | | expect(result.text).toContain("<q-block>second question</q-block>"); |
| 35 | expect(result.text).toContain( |
| 36 | "<q-block>first question<br>second question</q-block>", |
| 37 | ); |
| 38 | 38 | } |
| 39 | 39 | }); |
| 40 | 40 | |
| ... | ... | @@ -73,7 +73,7 @@ describe("clover extensions", () => { |
| 73 | 73 | expect(result.success).toBe(true); |
| 74 | 74 | if (result.success) { |
| 75 | 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 | 102 | expect(result.success).toBe(true); |
| 103 | 103 | if (result.success) { |
| 104 | 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 | 117 | if (result.success) { |
| 118 | 118 | expect(result.text).toContain("<artifact-ref>first-one</artifact-ref>"); |
| 119 | 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 | 131 | expect(result.success).toBe(true); |
| 132 | 132 | if (result.success) { |
| 133 | 133 | expect(result.text).toContain( |
| 134 | | "<artifact-ref>valid-slug123</artifact-ref>" |
| 134 | "<artifact-ref>valid-slug123</artifact-ref>", |
| 135 | 135 | ); |
| 136 | 136 | expect(result.text).toContain("@INVALID"); |
| 137 | 137 | expect(result.text).not.toContain("<artifact-ref>INVALID"); |
| ... | ... | @@ -161,7 +161,7 @@ describe("clover extensions", () => { |
| 161 | 161 | expect(result.success).toBe(true); |
| 162 | 162 | if (result.success) { |
| 163 | 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 | 175 | expect(result.success).toBe(true); |
| 176 | 176 | if (result.success) { |
| 177 | 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 | 205 | expect(result.success).toBe(true); |
| 206 | 206 | if (result.success) { |
| 207 | 207 | expect(result.text).toContain( |
| 208 | | "<question-ref>2602142011</question-ref>" |
| 208 | "<question-ref>2602142011</question-ref>", |
| 209 | 209 | ); |
| 210 | 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 | 217 | describe("labelled redactions", () => { |
| 218 | | it("transforms ##label## to redaction element", () => { |
| 218 | it("transforms #label# to redaction element", () => { |
| 219 | 219 | const result = transform({ |
| 220 | | source: "the ##secret name## is hidden", |
| 220 | source: "the #name# is hidden", |
| 221 | 221 | markdownOnly: true, |
| 222 | 222 | cloverExtensions, |
| 223 | 223 | }); |
| 224 | 224 | expect(result.success).toBe(true); |
| 225 | 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 | 230 | it("handles hyphens and underscores in labels", () => { |
| 231 | 231 | const result = transform({ |
| 232 | | source: "##my-secret_label##", |
| 232 | source: "#my-secret_label#", |
| 233 | 233 | markdownOnly: true, |
| 234 | 234 | cloverExtensions, |
| 235 | 235 | }); |
| ... | ... | @@ -241,21 +241,21 @@ describe("clover extensions", () => { |
| 241 | 241 | |
| 242 | 242 | it("does not match empty labels", () => { |
| 243 | 243 | const result = transform({ |
| 244 | | source: "text #### more", |
| 244 | source: "text ## ### #### more", |
| 245 | 245 | markdownOnly: true, |
| 246 | 246 | cloverExtensions, |
| 247 | 247 | }); |
| 248 | 248 | expect(result.success).toBe(true); |
| 249 | 249 | if (result.success) { |
| 250 | | expect(result.text).not.toContain("<redacted></redacted>"); |
| 251 | | // #### in the middle of text stays as-is |
| 252 | | expect(result.text).toContain("####"); |
| 250 | expect(result.text).not.toContain("<redacted>"); |
| 251 | // ## in the middle of text stays as-is |
| 252 | expect(result.text).toContain("##"); |
| 253 | 253 | } |
| 254 | 254 | }); |
| 255 | 255 | |
| 256 | 256 | it("handles multiple redactions", () => { |
| 257 | 257 | const result = transform({ |
| 258 | | source: "##first## and ##second##", |
| 258 | source: "#first# and #second#", |
| 259 | 259 | markdownOnly: true, |
| 260 | 260 | cloverExtensions, |
| 261 | 261 | }); |
| ... | ... | @@ -273,7 +273,7 @@ describe("clover extensions", () => { |
| 273 | 273 | source: `q: what is @some-artifact about? |
| 274 | 274 | q: also see #2602142011 |
| 275 | 275 | |
| 276 | | The ##secret## is revealed. |
| 276 | The #secret# is revealed. |
| 277 | 277 | |
| 278 | 278 | @html <hr class="divider" />`, |
| 279 | 279 | markdownOnly: true, |
| ... | ... | @@ -281,12 +281,12 @@ The ##secret## is revealed. |
| 281 | 281 | }); |
| 282 | 282 | expect(result.success).toBe(true); |
| 283 | 283 | if (result.success) { |
| 284 | | expect(result.text).toContain("<q-block>"); |
| 285 | | expect(result.text).toContain("<artifact-ref>some-artifact</artifact-ref>"); |
| 286 | | expect(result.text).toContain("<question-ref>2602142011</question-ref>"); |
| 287 | | expect(result.text).toContain("<redacted>secret</redacted>"); |
| 288 | | expect(result.text).toContain('<hr class="divider" />'); |
| 289 | | expect(result.text).toContain("<br />"); // between consecutive q: lines |
| 284 | expect(result.text).toBe( |
| 285 | `<q-block>what is <artifact-ref>some-artifact</artifact-ref> about?<br>also see <question-ref>2602142011</question-ref></q-block> |
| 286 | <p>The <redacted>secret</redacted> is revealed.</p> |
| 287 | <hr class="divider" /> |
| 288 | `, |
| 289 | ); |
| 290 | 290 | } |
| 291 | 291 | }); |
| 292 | 292 | |
| ... | ... | @@ -306,7 +306,8 @@ The ##secret## is revealed. |
| 306 | 306 | describe("without cloverExtensions", () => { |
| 307 | 307 | it("does not parse clover syntax when extensions not provided", () => { |
| 308 | 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 | 311 | markdownOnly: true, |
| 311 | 312 | }); |
| 312 | 313 | expect(result.success).toBe(true); |
| ... | ... | @@ -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 | }); |