-
-
Notifications
You must be signed in to change notification settings - Fork 2
test: add linting integration tests #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9594ab9
chore(deps): add textlint-rule-preset-ja-technical-writing to devDepe…
3w36zj6 319f798
refactor: move unit test files to `unit` directory
3w36zj6 d79d656
test: add linting integration tests
3w36zj6 2ba2503
test: refactor linting tests to reduce duplication
3w36zj6 42041f7
test: use preset rules configuration
3w36zj6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
test/integration/fixtures/smoke/textlint-rule-preset-ja-technical-writing/main.typ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| = textlint for Typst | ||
|
|
||
| == sentence-length | ||
|
|
||
| あいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえお。 | ||
|
|
||
| == max-comma | ||
|
|
||
| 組版処理システムの例としては、Tex (LaTeX), SATySFi, Typst, Twight, SILEなどがあります。 | ||
|
|
||
| == max-ten | ||
|
|
||
| これは、これは、これは、これは、これはだめ。 | ||
|
|
||
| == max-kanji-continuous-len | ||
|
|
||
| 情報処理学会は、電気学会、照明学会、応用物理学会、映像情報メディア学会および電子情報通信学会とともに電気系6学会の1つに数えられる存在です。 | ||
|
|
||
| == arabic-kanji-numbers | ||
|
|
||
| Fibonacci数列の十番目の項は55です。 | ||
|
|
||
| 1時的なファイルは`/tmp`に保存されます。 | ||
|
|
||
| == no-mix-dearu-desumasu | ||
|
|
||
| 今日はいい天気ですね。今日はいい天気である。 | ||
|
|
||
| == no-mixed-period | ||
|
|
||
| これは問題ないです。 | ||
|
|
||
| 「これはセリフ」 | ||
|
|
||
| english only | ||
|
|
||
| これは句点がありません | ||
|
|
||
| == no-double-negative-ja | ||
|
|
||
| それが事件の発端だったといえなくもない。 | ||
|
|
||
| 確かにそういった懸念はない事はない。 | ||
|
|
||
| == no-dropping-the-ra | ||
|
|
||
| お刺身を食べれない。 | ||
|
|
||
| == no-doubled-conjunctive-particle-ga | ||
|
|
||
| 今日は早朝から出発したが、定刻には間に合わなかったが、無事会場に到着した。 | ||
|
|
||
| == no-doubled-conjunction | ||
|
|
||
| かな漢字変換により漢字が多用される傾向がある。しかし漢字の多用が読みにくさをもたらす側面は否定できない。しかし、平仮名が多い文は間延びした印象を与える恐れもある。 | ||
|
|
||
| == no-doubled-joshi | ||
|
|
||
| 私は彼は好きだ。 | ||
|
|
||
| == no-nfd | ||
|
|
||
| ホ゜ケット エンシ゛ン。 | ||
|
|
||
| == no-exclamation-question-mark | ||
|
|
||
| 技術文書では、感嘆符、疑問符は基本的には使用しないでください! | ||
|
|
||
| == no-hankaku-kana | ||
|
|
||
| 半角カタカナを使用しないでください。 | ||
|
|
||
| == no-weak-phrase | ||
|
|
||
| この表現には問題があるかもしれないです。 | ||
|
|
||
| == no-successive-word | ||
|
|
||
| これは問題ない文章です。 | ||
|
|
||
| これはは問題ある文章です。 | ||
|
|
||
| これは問題あるある文章です。 | ||
|
|
||
| == no-abusage | ||
|
|
||
| ウインドウ幅が可変すると、レイアウトが崩れる。 | ||
|
|
||
| 今朝起きた事件に法律を適応する。 | ||
|
|
||
| == no-redundant-expression | ||
|
|
||
| これは省略することが可能です。 | ||
|
|
||
| == ja-unnatural-alphabet | ||
|
|
||
| リイr−ス。 | ||
|
|
||
| == no-unmatched-pair | ||
|
|
||
| これは(秘密)です。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import { | ||
| TextlintKernel, | ||
| type TextlintKernelRule, | ||
| type TextlintResult, | ||
| } from "@textlint/kernel"; | ||
| // @ts-expect-error | ||
| import { rules, rulesConfig } from "textlint-rule-preset-ja-technical-writing"; | ||
|
|
||
| import { beforeAll, describe, expect, it } from "vitest"; | ||
|
|
||
| import typstPlugin from "../../src"; | ||
|
|
||
| describe("linting", () => { | ||
| describe("smoke tests", () => { | ||
| describe("textlint-rule-preset-ja-technical-writing", () => { | ||
| let textlintResult: TextlintResult; | ||
|
|
||
| beforeAll(async () => { | ||
| const kernel = new TextlintKernel(); | ||
| textlintResult = await kernel.lintText( | ||
| fs.readFileSync( | ||
| path.join( | ||
| __dirname, | ||
| "./fixtures/smoke/textlint-rule-preset-ja-technical-writing/main.typ", | ||
| ), | ||
| "utf-8", | ||
| ), | ||
| { | ||
| ext: ".typ", | ||
| plugins: [ | ||
| { | ||
| pluginId: "typst", | ||
| plugin: typstPlugin, | ||
| }, | ||
| ], | ||
| rules: [ | ||
| // Set each rule in the preset individually | ||
| ...Object.entries(rules).map( | ||
| ([id, rule]) => | ||
| ({ | ||
| ruleId: `ja-technical-writing/${id}`, | ||
| rule: rule, | ||
| options: rulesConfig[id] || true, | ||
| }) as TextlintKernelRule, | ||
| ), | ||
| ], | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| // Rule test configurations | ||
| const ruleTests = [ | ||
| { | ||
| ruleId: "sentence-length", | ||
| expectedMessage: "exceeds the maximum sentence length", | ||
| }, | ||
| { | ||
| ruleId: "max-ten", | ||
| expectedMessage: '一つの文で"、"を4つ以上使用', | ||
| }, | ||
| { | ||
| ruleId: "max-kanji-continuous-len", | ||
| expectedMessage: "漢字が7つ以上連続", | ||
| }, | ||
| { | ||
| ruleId: "no-mix-dearu-desumasu", | ||
| expectedMessage: '"ですます"調 でなければなりません', | ||
| }, | ||
| { | ||
| ruleId: "ja-no-mixed-period", | ||
| expectedMessage: '文末が"。"で終わっていません', | ||
| }, | ||
| { | ||
| ruleId: "no-doubled-joshi", | ||
| expectedMessage: "一文に二回以上利用されている助詞", | ||
| }, | ||
| { | ||
| ruleId: "no-dropping-the-ra", | ||
| expectedMessage: "ら抜き言葉を使用", | ||
| }, | ||
| { | ||
| ruleId: "no-doubled-conjunctive-particle-ga", | ||
| expectedMessage: '逆接の接続助詞 "が" が二回以上使われています', | ||
| }, | ||
| { | ||
| ruleId: "no-doubled-conjunction", | ||
| expectedMessage: "同じ接続詞(しかし)が連続", | ||
| }, | ||
| { | ||
| ruleId: "no-exclamation-question-mark", | ||
| expectedMessage: 'Disallow to use "!"', | ||
| }, | ||
| { | ||
| ruleId: "no-hankaku-kana", | ||
| expectedMessage: "Disallow to use 半角カタカナ", | ||
| }, | ||
| { | ||
| ruleId: "ja-no-weak-phrase", | ||
| expectedMessage: '弱い表現: "かも" が使われています', | ||
| }, | ||
| { | ||
| ruleId: "ja-no-successive-word", | ||
| expectedMessage: "が連続して2回使われています", | ||
| }, | ||
| { | ||
| ruleId: "ja-no-redundant-expression", | ||
| expectedMessage: 'することが可能です"は冗長な表現', | ||
| }, | ||
| { | ||
| ruleId: "ja-unnatural-alphabet", | ||
| expectedMessage: "不自然なアルファベット", | ||
| }, | ||
| { | ||
| ruleId: "no-unmatched-pair", | ||
| expectedMessage: "Cannot find a pairing character for (", | ||
| }, | ||
| ]; | ||
|
|
||
| // Special cases with multiple expected messages | ||
| const multiMessageTests = [ | ||
| { | ||
| ruleId: "arabic-kanji-numbers", | ||
| expectedMessages: ["十番目 => 10番目", "1時的 => 一時的"], | ||
| }, | ||
| { | ||
| ruleId: "no-double-negative-ja", | ||
| expectedMessages: [ | ||
| "二重否定: 〜なくもない", | ||
| "二重否定: 〜ないことはない", | ||
| ], | ||
| }, | ||
| { | ||
| ruleId: "no-nfd", | ||
| expectedMessages: ['ホ゜" => "ポ"', 'シ゛" => "ジ"'], | ||
| }, | ||
| { | ||
| ruleId: "ja-no-abusage", | ||
| expectedMessages: ["可変する", "適用"], | ||
| }, | ||
| ]; | ||
|
|
||
| const getViolations = (ruleId: string) => { | ||
| return textlintResult.messages.filter( | ||
| (message) => message.ruleId === `ja-technical-writing/${ruleId}`, | ||
| ); | ||
| }; | ||
|
|
||
| // Single message tests | ||
| for (const { ruleId, expectedMessage } of ruleTests) { | ||
| it(`should detect ${ruleId} violations`, () => { | ||
| const violations = getViolations(ruleId); | ||
| expect(violations.length).toBeGreaterThan(0); | ||
| expect(violations[0].message).toContain(expectedMessage); | ||
| }); | ||
| } | ||
|
|
||
| // Multi-message tests | ||
| for (const { ruleId, expectedMessages } of multiMessageTests) { | ||
| it(`should detect ${ruleId} violations`, () => { | ||
| const violations = getViolations(ruleId); | ||
| expect(violations.length).toBeGreaterThan(0); | ||
|
|
||
| for (const expectedMessage of expectedMessages) { | ||
| expect( | ||
| violations.some((v) => v.message.includes(expectedMessage)), | ||
| ).toBe(true); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.