~ubuntu-branches/debian/sid/neovim/sid

« back to all changes in this revision

Viewing changes to test/functional/eval/string_spec.lua

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2016-04-18 21:42:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20160418214219-1e6d4o1fwqarzk46
Tags: 0.1.3-1
* New upstream release.  (Closes: #820562)
* debian/control:
  + Remove unnecessary luarocks Build-Depends
  + Add libkvm-dev Build-Depends for kfreebsd-*
  + Add python(3)-neovim to Recommends.  (Closes: #812737)
  + Declare compiance with policy 3.9.8, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
local helpers = require('test.functional.helpers')
 
2
local clear = helpers.clear
 
3
local eq = helpers.eq
 
4
local command = helpers.command
 
5
local meths = helpers.meths
 
6
local eval = helpers.eval
 
7
local exc_exec = helpers.exc_exec
 
8
local redir_exec = helpers.redir_exec
 
9
local funcs = helpers.funcs
 
10
local write_file = helpers.write_file
 
11
 
 
12
describe('string() function', function()
 
13
  before_each(clear)
 
14
 
 
15
  describe('used to represent floating-point values', function()
 
16
    it('dumps NaN values', function()
 
17
      eq('str2float(\'nan\')', eval('string(str2float(\'nan\'))'))
 
18
    end)
 
19
 
 
20
    it('dumps infinite values', function()
 
21
      eq('str2float(\'inf\')', eval('string(str2float(\'inf\'))'))
 
22
      eq('-str2float(\'inf\')', eval('string(str2float(\'-inf\'))'))
 
23
    end)
 
24
 
 
25
    it('dumps regular values', function()
 
26
      eq('1.5', funcs.string(1.5))
 
27
      eq('1.56e-20', funcs.string(1.56000e-020))
 
28
      eq('0.0', eval('string(0.0)'))
 
29
    end)
 
30
 
 
31
    it('dumps values with at most six digits after the decimal point',
 
32
    function()
 
33
      eq('1.234568e-20', funcs.string(1.23456789123456789123456789e-020))
 
34
      eq('1.234568', funcs.string(1.23456789123456789123456789))
 
35
    end)
 
36
 
 
37
    it('dumps values with at most seven digits before the decimal point',
 
38
    function()
 
39
      eq('1234567.891235', funcs.string(1234567.89123456789123456789))
 
40
      eq('1.234568e7', funcs.string(12345678.9123456789123456789))
 
41
    end)
 
42
 
 
43
    it('dumps negative values', function()
 
44
      eq('-1.5', funcs.string(-1.5))
 
45
      eq('-1.56e-20', funcs.string(-1.56000e-020))
 
46
      eq('-1.234568e-20', funcs.string(-1.23456789123456789123456789e-020))
 
47
      eq('-1.234568', funcs.string(-1.23456789123456789123456789))
 
48
      eq('-1234567.891235', funcs.string(-1234567.89123456789123456789))
 
49
      eq('-1.234568e7', funcs.string(-12345678.9123456789123456789))
 
50
    end)
 
51
  end)
 
52
 
 
53
  describe('used to represent numbers', function()
 
54
    it('dumps regular values', function()
 
55
      eq('0', funcs.string(0))
 
56
      eq('-1', funcs.string(-1))
 
57
      eq('1', funcs.string(1))
 
58
    end)
 
59
 
 
60
    it('dumps large values', function()
 
61
      eq('2147483647', funcs.string(2^31-1))
 
62
      eq('-2147483648', funcs.string(-2^31))
 
63
    end)
 
64
  end)
 
65
 
 
66
  describe('used to represent strings', function()
 
67
    it('dumps regular strings', function()
 
68
      eq('\'test\'', funcs.string('test'))
 
69
    end)
 
70
 
 
71
    it('dumps empty strings', function()
 
72
      eq('\'\'', funcs.string(''))
 
73
    end)
 
74
 
 
75
    it('dumps strings with \' inside', function()
 
76
      eq('\'\'\'\'\'\'\'\'', funcs.string('\'\'\''))
 
77
      eq('\'a\'\'b\'\'\'\'\'', funcs.string('a\'b\'\''))
 
78
      eq('\'\'\'b\'\'\'\'d\'', funcs.string('\'b\'\'d'))
 
79
      eq('\'a\'\'b\'\'c\'\'d\'', funcs.string('a\'b\'c\'d'))
 
80
    end)
 
81
  end)
 
82
 
 
83
  describe('used to represent funcrefs', function()
 
84
    local fname = 'Xtest-functional-eval-string_spec-fref-script.vim'
 
85
 
 
86
    before_each(function()
 
87
      write_file(fname, [[
 
88
        function Test1()
 
89
        endfunction
 
90
 
 
91
        function s:Test2()
 
92
        endfunction
 
93
 
 
94
        function g:Test3()
 
95
        endfunction
 
96
 
 
97
        let g:Test2_f = function('s:Test2')
 
98
      ]])
 
99
      command('source ' .. fname)
 
100
    end)
 
101
 
 
102
    after_each(function()
 
103
      os.remove(fname)
 
104
    end)
 
105
 
 
106
    it('dumps references to built-in functions', function()
 
107
      eq('function(\'function\')', eval('string(function("function"))'))
 
108
    end)
 
109
 
 
110
    it('dumps references to user functions', function()
 
111
      eq('function(\'Test1\')', eval('string(function("Test1"))'))
 
112
      eq('function(\'g:Test3\')', eval('string(function("g:Test3"))'))
 
113
    end)
 
114
 
 
115
    it('dumps references to script functions', function()
 
116
      eq('function(\'<SNR>1_Test2\')', eval('string(Test2_f)'))
 
117
    end)
 
118
  end)
 
119
 
 
120
  describe('used to represent lists', function()
 
121
    it('dumps empty list', function()
 
122
      eq('[]', funcs.string({}))
 
123
    end)
 
124
 
 
125
    it('dumps nested lists', function()
 
126
      eq('[[[[[]]]]]', funcs.string({{{{{}}}}}))
 
127
    end)
 
128
 
 
129
    it('dumps nested non-empty lists', function()
 
130
      eq('[1, [[3, [[5], 4]], 2]]', funcs.string({1, {{3, {{5}, 4}}, 2}}))
 
131
    end)
 
132
 
 
133
    it('errors when dumping recursive lists', function()
 
134
      meths.set_var('l', {})
 
135
      eval('add(l, l)')
 
136
      eq('Vim(echo):E724: unable to correctly dump variable with self-referencing container',
 
137
         exc_exec('echo string(l)'))
 
138
    end)
 
139
 
 
140
    it('dumps recursive lists despite the error', function()
 
141
      meths.set_var('l', {})
 
142
      eval('add(l, l)')
 
143
      eq('\nE724: unable to correctly dump variable with self-referencing container\n[{E724@0}]',
 
144
         redir_exec('echo string(l)'))
 
145
      eq('\nE724: unable to correctly dump variable with self-referencing container\n[[{E724@1}]]',
 
146
         redir_exec('echo string([l])'))
 
147
    end)
 
148
  end)
 
149
 
 
150
  describe('used to represent dictionaries', function()
 
151
    it('dumps empty dictionary', function()
 
152
      eq('{}', eval('string({})'))
 
153
    end)
 
154
 
 
155
    it('dumps non-empty dictionary', function()
 
156
      eq('{\'t\'\'est\': 1}', funcs.string({['t\'est']=1}))
 
157
    end)
 
158
 
 
159
    it('errors when dumping recursive dictionaries', function()
 
160
      meths.set_var('d', {d=1})
 
161
      eval('extend(d, {"d": d})')
 
162
      eq('Vim(echo):E724: unable to correctly dump variable with self-referencing container',
 
163
         exc_exec('echo string(d)'))
 
164
    end)
 
165
 
 
166
    it('dumps recursive dictionaries despite the error', function()
 
167
      meths.set_var('d', {d=1})
 
168
      eval('extend(d, {"d": d})')
 
169
      eq('\nE724: unable to correctly dump variable with self-referencing container\n{\'d\': {E724@0}}',
 
170
         redir_exec('echo string(d)'))
 
171
      eq('\nE724: unable to correctly dump variable with self-referencing container\n{\'out\': {\'d\': {E724@1}}}',
 
172
         redir_exec('echo string({"out": d})'))
 
173
    end)
 
174
  end)
 
175
end)