File: punycode_spec.cr

package info (click to toggle)
crystal 1.6.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,956 kB
  • sloc: javascript: 1,712; sh: 592; cpp: 541; makefile: 243; ansic: 119; python: 105; xml: 32
file content (29 lines) | stat: -rw-r--r-- 988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require "spec"
require "uri/punycode"

describe URI::Punycode do
  [
    {"3年B組金八先生", "3B-ww4c5e180e575a65lsy2b"},
    {"安室奈美恵-with-SUPER-MONKEYS", "-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n"},
    {"Hello-Another-Way-それぞれの場所", "Hello-Another-Way--fc4qua05auwb3674vfr0b"},
    {"ひとつ屋根の下2", "2-u9tlzr9756bt3uc0v"},
    {"MajiでKoiする5秒前", "MajiKoi5-783gue6qz075azm5e"},
    {"パフィーdeルンバ", "de-jg4avhby1noc0d"},
    {"そのスピードで", "d9juau41awczczp"},
    {"Hello-Another-Way-それぞれ", "Hello-Another-Way--fc4qua97gba"},
  ].each do |example|
    dec, enc = example

    it "encodes #{dec} to #{enc}" do
      URI::Punycode.encode(dec).should eq enc
    end

    it "decodes #{enc} to #{dec}" do
      URI::Punycode.decode(enc).should eq dec
    end
  end

  it "translate to ascii only host name" do
    URI::Punycode.to_ascii("test.テスト.テスト").should eq "test.xn--zckzah.xn--zckzah"
  end
end