File: unicode.moon

package info (click to toggle)
aegisub 3.2.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 21,852 kB
  • sloc: cpp: 56,932; ansic: 16,422; asm: 3,618; sh: 3,582; makefile: 407; python: 350; perl: 274; cs: 205; xml: 196; objc: 47
file content (47 lines) | stat: -rw-r--r-- 2,059 bytes parent folder | download | duplicates (5)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- Copyright (c) 2013, Thomas Goyne <plorkyeran@aegisub.org>
--
-- Permission to use, copy, modify, and distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

unicode = require 'aegisub.unicode'

describe 'charwidth', ->
  it 'should return 1 for an ascii character', ->
    assert.is.equal 1, unicode.charwidth 'a'
  it 'should return 2 for a two byte character', ->
    assert.is.equal 2, unicode.charwidth 'ß'
  it 'should return 3 for a three byte character', ->
    assert.is.equal 3, unicode.charwidth 'c'
  it 'should return 4 for a four byte character', ->
    assert.is.equal 4, unicode.charwidth 'šŸ„“'

describe 'char_iterator', ->
  it 'should iterator over multi-byte codepoints', ->
    chars = [c for c in unicode.chars 'aĆŸļ½ƒšŸ„“']
    assert.is.equal 4, #chars
    assert.is.equal chars[1], 'a'
    assert.is.equal chars[2], 'ß'
    assert.is.equal chars[3], 'c'
    assert.is.equal chars[4], 'šŸ„“'

describe 'len', ->
  it 'should give length in codepoints', ->
    assert.is.equal 4, unicode.len 'aĆŸļ½ƒšŸ„“'

describe 'codepoint', ->
  it 'should give codepoint as an integer for a string', ->
    assert.is.equal 97, unicode.codepoint 'a'
    assert.is.equal 223, unicode.codepoint 'ß'
    assert.is.equal 0xFF43, unicode.codepoint 'c'
    assert.is.equal 0x1F113, unicode.codepoint 'šŸ„“'
  it 'should give ignore codepoints after the first', ->
    assert.is.equal 97, unicode.codepoint 'abc'