File: zig_spec.rb

package info (click to toggle)
ruby-rouge 4.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,844 kB
  • sloc: ruby: 38,489; sed: 2,071; perl: 152; makefile: 8
file content (57 lines) | stat: -rw-r--r-- 1,542 bytes parent folder | download | duplicates (4)
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
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

describe Rouge::Lexers::Zig do
  let(:subject) { Rouge::Lexers::Zig.new }

  describe 'guessing' do
    include Support::Guessing

    it 'guesses by filename' do
      assert_guess :filename => 'foo.zig'
    end

    it 'guesses by mimetype' do
      assert_guess :mimetype => 'text/x-zig'
    end
  end

  describe 'lexing' do
    include Support::Lexing;

    it 'classifies identifiers' do
      assert_tokens_equal 'var x: i32 = 100;',
        ['Keyword', 'var'],
        ['Text', ' '],
        ['Name', 'x'],
        ['Punctuation', ':'],
        ['Text', ' '],
        ['Keyword.Type', 'i32'],
        ['Text', ' '],
        ['Operator', '='],
        ['Text', ' '],
        ['Literal.Number.Integer', '100'],
        ['Punctuation', ';']

      assert_tokens_equal 'var x: f32 = 1.01;',
        ['Keyword', 'var'],
        ['Text', ' '],
        ['Name', 'x'],
        ['Punctuation', ':'],
        ['Text', ' '],
        ['Keyword.Type', 'f32'],
        ['Text', ' '],
        ['Operator', '='],
        ['Text', ' '],
        ['Literal.Number.Float', '1.01'],
        ['Punctuation', ';']
    end

    it 'recognizes exponents in integers and reals' do
      assert_tokens_equal '1e6', ['Literal.Number.Float', '1e6']
      assert_tokens_equal '123_456', ['Literal.Number.Integer', '123_456']
      assert_tokens_equal '3.14159_26', ['Literal.Number.Float', '3.14159_26']
      assert_tokens_equal '3.141_592e-20', ['Literal.Number.Float', '3.141_592e-20']
    end
  end
end