mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	Normalize nan/-nan in plugin/msgpack_spec.lua
-NaN doesn't exist in the IEEE 754 spec, it is a hardware-specific detail abstracted away by luajit(and not by lua or nvim), so there's no need to test it. Normalize all tests that involve -nan so the suite will be compatible with both Lua and Luajit.
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| local helpers = require('test.functional.helpers') | local helpers = require('test.functional.helpers') | ||||||
| local eq, nvim_eval, nvim_command, exc_exec = | local eq, nvim_eval, nvim_command, exc_exec = | ||||||
|   helpers.eq, helpers.eval, helpers.command, helpers.exc_exec |   helpers.eq, helpers.eval, helpers.command, helpers.exc_exec | ||||||
|  | local ok = helpers.ok | ||||||
|  |  | ||||||
| local plugin_helpers = require('test.functional.plugin.helpers') | local plugin_helpers = require('test.functional.plugin.helpers') | ||||||
| local reset = plugin_helpers.reset | local reset = plugin_helpers.reset | ||||||
| @@ -21,10 +22,8 @@ describe('In autoload/msgpack.vim', function() | |||||||
|   end |   end | ||||||
|  |  | ||||||
|   local nan = -(1.0/0.0-1.0/0.0) |   local nan = -(1.0/0.0-1.0/0.0) | ||||||
|   local minus_nan = 1.0/0.0-1.0/0.0 |  | ||||||
|   local inf = 1.0/0.0 |   local inf = 1.0/0.0 | ||||||
|   local minus_inf = -(1.0/0.0) |   local minus_inf = -(1.0/0.0) | ||||||
|   local has_minus_nan = tostring(nan) ~= tostring(minus_nan) |  | ||||||
|  |  | ||||||
|   describe('function msgpack#equal', function() |   describe('function msgpack#equal', function() | ||||||
|     local msgpack_eq = function(expected, a, b) |     local msgpack_eq = function(expected, a, b) | ||||||
| @@ -160,9 +159,9 @@ describe('In autoload/msgpack.vim', function() | |||||||
|     it('compares raw floats correctly', function() |     it('compares raw floats correctly', function() | ||||||
|       msgpack_eq(1, '0.0', '0.0') |       msgpack_eq(1, '0.0', '0.0') | ||||||
|       msgpack_eq(1, '(1.0/0.0-1.0/0.0)', '(1.0/0.0-1.0/0.0)') |       msgpack_eq(1, '(1.0/0.0-1.0/0.0)', '(1.0/0.0-1.0/0.0)') | ||||||
|       if has_minus_nan then |       -- both (1.0/0.0-1.0/0.0) and -(1.0/0.0-1.0/0.0) now return | ||||||
|         msgpack_eq(0, '(1.0/0.0-1.0/0.0)', '-(1.0/0.0-1.0/0.0)') |       -- str2float('nan'). ref: @18d1ba3422d | ||||||
|       end |       msgpack_eq(1, '(1.0/0.0-1.0/0.0)', '-(1.0/0.0-1.0/0.0)') | ||||||
|       msgpack_eq(1, '-(1.0/0.0-1.0/0.0)', '-(1.0/0.0-1.0/0.0)') |       msgpack_eq(1, '-(1.0/0.0-1.0/0.0)', '-(1.0/0.0-1.0/0.0)') | ||||||
|       msgpack_eq(1, '1.0/0.0', '1.0/0.0') |       msgpack_eq(1, '1.0/0.0', '1.0/0.0') | ||||||
|       msgpack_eq(1, '-(1.0/0.0)', '-(1.0/0.0)') |       msgpack_eq(1, '-(1.0/0.0)', '-(1.0/0.0)') | ||||||
| @@ -178,10 +177,8 @@ describe('In autoload/msgpack.vim', function() | |||||||
|     it('compares float specials with raw floats correctly', function() |     it('compares float specials with raw floats correctly', function() | ||||||
|       msgpack_eq(1, sp('float', '0.0'), '0.0') |       msgpack_eq(1, sp('float', '0.0'), '0.0') | ||||||
|       msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), '(1.0/0.0-1.0/0.0)') |       msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), '(1.0/0.0-1.0/0.0)') | ||||||
|       if has_minus_nan then |       msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), '-(1.0/0.0-1.0/0.0)') | ||||||
|         msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), '-(1.0/0.0-1.0/0.0)') |       msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), '(1.0/0.0-1.0/0.0)') | ||||||
|         msgpack_eq(0, sp('float', '-(1.0/0.0-1.0/0.0)'), '(1.0/0.0-1.0/0.0)') |  | ||||||
|       end |  | ||||||
|       msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), '-(1.0/0.0-1.0/0.0)') |       msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), '-(1.0/0.0-1.0/0.0)') | ||||||
|       msgpack_eq(1, sp('float', '1.0/0.0'), '1.0/0.0') |       msgpack_eq(1, sp('float', '1.0/0.0'), '1.0/0.0') | ||||||
|       msgpack_eq(1, sp('float', '-(1.0/0.0)'), '-(1.0/0.0)') |       msgpack_eq(1, sp('float', '-(1.0/0.0)'), '-(1.0/0.0)') | ||||||
| @@ -207,10 +204,8 @@ describe('In autoload/msgpack.vim', function() | |||||||
|       msgpack_eq(0, sp('float', '0.0'), sp('float', '-(1.0/0.0)')) |       msgpack_eq(0, sp('float', '0.0'), sp('float', '-(1.0/0.0)')) | ||||||
|       msgpack_eq(0, sp('float', '1.0/0.0'), sp('float', '-(1.0/0.0)')) |       msgpack_eq(0, sp('float', '1.0/0.0'), sp('float', '-(1.0/0.0)')) | ||||||
|       msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '-(1.0/0.0)')) |       msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '-(1.0/0.0)')) | ||||||
|       if has_minus_nan then |       msgpack_eq(1, sp('float', '(1.0/0.0-1.0/0.0)'), | ||||||
|         msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), |  | ||||||
|                     sp('float', '-(1.0/0.0-1.0/0.0)')) |                     sp('float', '-(1.0/0.0-1.0/0.0)')) | ||||||
|       end |  | ||||||
|       msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), |       msgpack_eq(1, sp('float', '-(1.0/0.0-1.0/0.0)'), | ||||||
|                     sp('float', '-(1.0/0.0-1.0/0.0)')) |                     sp('float', '-(1.0/0.0-1.0/0.0)')) | ||||||
|       msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '1.0/0.0')) |       msgpack_eq(0, sp('float', '(1.0/0.0-1.0/0.0)'), sp('float', '1.0/0.0')) | ||||||
| @@ -392,9 +387,7 @@ describe('In autoload/msgpack.vim', function() | |||||||
|       string_eq('0.0', sp('float', '0.0')) |       string_eq('0.0', sp('float', '0.0')) | ||||||
|       string_eq('inf', sp('float', '(1.0/0.0)')) |       string_eq('inf', sp('float', '(1.0/0.0)')) | ||||||
|       string_eq('-inf', sp('float', '-(1.0/0.0)')) |       string_eq('-inf', sp('float', '-(1.0/0.0)')) | ||||||
|       if has_minus_nan then |       string_eq('nan', sp('float', '(1.0/0.0-1.0/0.0)')) | ||||||
|         string_eq('-nan', sp('float', '(1.0/0.0-1.0/0.0)')) |  | ||||||
|       end |  | ||||||
|       string_eq('nan', sp('float', '-(1.0/0.0-1.0/0.0)')) |       string_eq('nan', sp('float', '-(1.0/0.0-1.0/0.0)')) | ||||||
|       string_eq('FALSE', sp('boolean', '0')) |       string_eq('FALSE', sp('boolean', '0')) | ||||||
|       string_eq('TRUE', sp('boolean', '1')) |       string_eq('TRUE', sp('boolean', '1')) | ||||||
| @@ -413,9 +406,7 @@ describe('In autoload/msgpack.vim', function() | |||||||
|       string_eq('0.0', '0.0') |       string_eq('0.0', '0.0') | ||||||
|       string_eq('inf', '(1.0/0.0)') |       string_eq('inf', '(1.0/0.0)') | ||||||
|       string_eq('-inf', '-(1.0/0.0)') |       string_eq('-inf', '-(1.0/0.0)') | ||||||
|       if has_minus_nan then |       string_eq('nan', '(1.0/0.0-1.0/0.0)') | ||||||
|         string_eq('-nan', '(1.0/0.0-1.0/0.0)') |  | ||||||
|       end |  | ||||||
|       string_eq('nan', '-(1.0/0.0-1.0/0.0)') |       string_eq('nan', '-(1.0/0.0-1.0/0.0)') | ||||||
|     end) |     end) | ||||||
|   end) |   end) | ||||||
| @@ -547,8 +538,11 @@ describe('In autoload/msgpack.vim', function() | |||||||
|       end |       end | ||||||
|       if expected_val_full == expected_val_full then |       if expected_val_full == expected_val_full then | ||||||
|         eq(expected_val_full, nvim_eval('g:__val')) |         eq(expected_val_full, nvim_eval('g:__val')) | ||||||
|       else |       else -- NaN | ||||||
|         eq(tostring(expected_val_full), tostring(nvim_eval('g:__val'))) |         local nvim_nan = tostring(nvim_eval('g:__val')) | ||||||
|  |         -- -NaN is a hardware-specific detail, there's no need to test for it. | ||||||
|  |         -- Accept ether 'nan' or '-nan' as the response. | ||||||
|  |         ok(nvim_nan == 'nan' or nvim_nan == '-nan') | ||||||
|       end |       end | ||||||
|       nvim_command('unlet g:__val') |       nvim_command('unlet g:__val') | ||||||
|     end |     end | ||||||
| @@ -615,7 +609,6 @@ describe('In autoload/msgpack.vim', function() | |||||||
|       eval_eq('float', inf, 'inf') |       eval_eq('float', inf, 'inf') | ||||||
|       eval_eq('float', minus_inf, '-inf') |       eval_eq('float', minus_inf, '-inf') | ||||||
|       eval_eq('float', nan, 'nan') |       eval_eq('float', nan, 'nan') | ||||||
|       eval_eq('float', minus_nan, '-nan') |  | ||||||
|       eval_eq('float', 1.0e10, '1.0e10') |       eval_eq('float', 1.0e10, '1.0e10') | ||||||
|       eval_eq('float', 1.0e10, '1.0e+10') |       eval_eq('float', 1.0e10, '1.0e+10') | ||||||
|       eval_eq('float', -1.0e10, '-1.0e+10') |       eval_eq('float', -1.0e10, '-1.0e+10') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Thiago de Arruda
					Thiago de Arruda