File: symbol_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 (34 lines) | stat: -rw-r--r-- 1,027 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
30
31
32
33
34
require "spec"

describe Symbol do
  it "inspects" do
    :foo.inspect.should eq(%(:foo))
    :"{".inspect.should eq(%(:"{"))
    :"hi there".inspect.should eq(%(:"hi there"))
    :"1a".inspect.should eq(%(:"1a"))
    # :かたな.inspect.should eq(%(:かたな))
  end

  it "can be compared with another symbol" do
    (:foo > :bar).should be_true
    (:foo < :bar).should be_false

    a = %i(q w e r t y u i o p a s d f g h j k l z x c v b n m)
    b = %i(a b c d e f g h i j k l m n o p q r s t u v w x y z)
    a.sort.should eq(b)
  end

  it "displays symbols that don't need quotes without quotes" do
    a = %i(+ - * / == < <= > >= ! != =~ !~ & | ^ ~ ** &** >> << % [] <=> === []? []=)
    b = "[:+, :-, :*, :/, :==, :<, :<=, :>, :>=, :!, :!=, :=~, :!~, :&, :|, :^, :~, :**, :&**, :>>, :<<, :%, :[], :<=>, :===, :[]?, :[]=]"
    a.inspect.should eq(b)
  end

  it "displays the empty symbol with quotes" do
    :"".inspect.should eq(%(:""))
  end

  describe "clone" do
    it { :foo.clone.should eq(:foo) }
  end
end