|
| 1 | +/** |
| 2 | + * @fileoverview Tests for no-unnormalized-keys rule. |
| 3 | + * @author Bradley Meck Farias |
| 4 | + */ |
| 5 | + |
| 6 | +//------------------------------------------------------------------------------ |
| 7 | +// Imports |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | +import rule from "../../src/rules/no-unnormalized-keys.js"; |
| 11 | +import json from "../../src/index.js"; |
| 12 | +import { RuleTester } from "eslint"; |
| 13 | + |
| 14 | +//------------------------------------------------------------------------------ |
| 15 | +// Tests |
| 16 | +//------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +const ruleTester = new RuleTester({ |
| 19 | + plugins: { |
| 20 | + json, |
| 21 | + }, |
| 22 | + language: "json/json", |
| 23 | +}); |
| 24 | + |
| 25 | +const o = "\u1E9B\u0323"; |
| 26 | + |
| 27 | +ruleTester.run("no-unnormalized-keys", rule, { |
| 28 | + valid: [ |
| 29 | + `{"${o}":"NFC"}`, |
| 30 | + { |
| 31 | + code: `{"${o}":"NFC"}`, |
| 32 | + options: [{ form: "NFC" }], |
| 33 | + }, |
| 34 | + { |
| 35 | + code: `{"${o.normalize("NFD")}":"NFD"}`, |
| 36 | + options: [{ form: "NFD" }], |
| 37 | + }, |
| 38 | + { |
| 39 | + code: `{"${o.normalize("NFKC")}":"NFKC"}`, |
| 40 | + options: [{ form: "NFKC" }], |
| 41 | + }, |
| 42 | + { |
| 43 | + code: `{"${o.normalize("NFKD")}":"NFKD"}`, |
| 44 | + options: [{ form: "NFKD" }], |
| 45 | + }, |
| 46 | + ], |
| 47 | + invalid: [ |
| 48 | + { |
| 49 | + code: `{"${o.normalize("NFD")}":"NFD"}`, |
| 50 | + errors: [ |
| 51 | + { |
| 52 | + messageId: "unnormalizedKey", |
| 53 | + data: { key: o.normalize("NFD") }, |
| 54 | + line: 1, |
| 55 | + column: 2, |
| 56 | + endLine: 1, |
| 57 | + endColumn: 7, |
| 58 | + }, |
| 59 | + ], |
| 60 | + }, |
| 61 | + { |
| 62 | + code: `{${o.normalize("NFD")}:"NFD"}`, |
| 63 | + language: "json/json5", |
| 64 | + errors: [ |
| 65 | + { |
| 66 | + messageId: "unnormalizedKey", |
| 67 | + data: { key: o.normalize("NFD") }, |
| 68 | + line: 1, |
| 69 | + column: 2, |
| 70 | + endLine: 1, |
| 71 | + endColumn: 5, |
| 72 | + }, |
| 73 | + ], |
| 74 | + }, |
| 75 | + { |
| 76 | + code: `{"${o.normalize("NFKC")}":"NFKC"}`, |
| 77 | + options: [{ form: "NFKD" }], |
| 78 | + errors: [ |
| 79 | + { |
| 80 | + messageId: "unnormalizedKey", |
| 81 | + data: { key: o.normalize("NFKC") }, |
| 82 | + line: 1, |
| 83 | + column: 2, |
| 84 | + endLine: 1, |
| 85 | + endColumn: 5, |
| 86 | + }, |
| 87 | + ], |
| 88 | + }, |
| 89 | + ], |
| 90 | +}); |
0 commit comments