comparison src/testdir/test_viml.vim @ 9157:e316b83892c1 v7.4.1862

commit https://github.com/vim/vim/commit/18dfb4404a618c52ee7138630a2381aed4d66eaf Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 31 22:31:23 2016 +0200 patch 7.4.1862 Problem: string() with repeated argument does not give a result usable by eval(). Solution: Refactor echo_striong and tv2string(), moving the common part to echo_string_core(). (Ken Takata)
author Christian Brabandt <cb@256bit.org>
date Tue, 31 May 2016 22:45:06 +0200
parents 80d78e1ab787
children 32e34e574716
comparison
equal deleted inserted replaced
9156:724c5ba6e649 9157:e316b83892c1
1051 call assert_false(0 && len(sp)) 1051 call assert_false(0 && len(sp))
1052 1052
1053 endfunc 1053 endfunc
1054 1054
1055 "------------------------------------------------------------------------------- 1055 "-------------------------------------------------------------------------------
1056 " Test 93: :echo and string() {{{1
1057 "-------------------------------------------------------------------------------
1058
1059 func Test_echo_and_string()
1060 " String
1061 let a = 'foo bar'
1062 redir => result
1063 echo a
1064 echo string(a)
1065 redir END
1066 let l = split(result, "\n")
1067 call assert_equal(["foo bar",
1068 \ "'foo bar'"], l)
1069
1070 " Float
1071 if has('float')
1072 let a = -1.2e0
1073 redir => result
1074 echo a
1075 echo string(a)
1076 redir END
1077 let l = split(result, "\n")
1078 call assert_equal(["-1.2",
1079 \ "-1.2"], l)
1080 endif
1081
1082 " Funcref
1083 redir => result
1084 echo function('string')
1085 echo string(function('string'))
1086 redir END
1087 let l = split(result, "\n")
1088 call assert_equal(["string",
1089 \ "function('string')"], l)
1090
1091 " Recursive dictionary
1092 let a = {}
1093 let a["a"] = a
1094 redir => result
1095 echo a
1096 echo string(a)
1097 redir END
1098 let l = split(result, "\n")
1099 call assert_equal(["{'a': {...}}",
1100 \ "{'a': {...}}"], l)
1101
1102 " Recursive list
1103 let a = [0]
1104 let a[0] = a
1105 redir => result
1106 echo a
1107 echo string(a)
1108 redir END
1109 let l = split(result, "\n")
1110 call assert_equal(["[[...]]",
1111 \ "[[...]]"], l)
1112
1113 " Empty dictionaries in a list
1114 let a = {}
1115 redir => result
1116 echo [a, a, a]
1117 echo string([a, a, a])
1118 redir END
1119 let l = split(result, "\n")
1120 call assert_equal(["[{}, {}, {}]",
1121 \ "[{}, {}, {}]"], l)
1122
1123 " Empty dictionaries in a dictionary
1124 let a = {}
1125 let b = {"a": a, "b": a}
1126 redir => result
1127 echo b
1128 echo string(b)
1129 redir END
1130 let l = split(result, "\n")
1131 call assert_equal(["{'a': {}, 'b': {}}",
1132 \ "{'a': {}, 'b': {}}"], l)
1133
1134 " Empty lists in a list
1135 let a = []
1136 redir => result
1137 echo [a, a, a]
1138 echo string([a, a, a])
1139 redir END
1140 let l = split(result, "\n")
1141 call assert_equal(["[[], [], []]",
1142 \ "[[], [], []]"], l)
1143
1144 " Empty lists in a dictionary
1145 let a = []
1146 let b = {"a": a, "b": a}
1147 redir => result
1148 echo b
1149 echo string(b)
1150 redir END
1151 let l = split(result, "\n")
1152 call assert_equal(["{'a': [], 'b': []}",
1153 \ "{'a': [], 'b': []}"], l)
1154
1155 " Dictionaries in a list
1156 let a = {"one": "yes", "two": "yes", "three": "yes"}
1157 redir => result
1158 echo [a, a, a]
1159 echo string([a, a, a])
1160 redir END
1161 let l = split(result, "\n")
1162 call assert_equal(["[{'one': 'yes', 'two': 'yes', 'three': 'yes'}, {...}, {...}]",
1163 \ "[{'one': 'yes', 'two': 'yes', 'three': 'yes'}, {'one': 'yes', 'two': 'yes', 'three': 'yes'}, {'one': 'yes', 'two': 'yes', 'three': 'yes'}]"], l)
1164
1165 " Dictionaries in a dictionary
1166 let a = {"one": "yes", "two": "yes", "three": "yes"}
1167 let b = {"a": a, "b": a}
1168 redir => result
1169 echo b
1170 echo string(b)
1171 redir END
1172 let l = split(result, "\n")
1173 call assert_equal(["{'a': {'one': 'yes', 'two': 'yes', 'three': 'yes'}, 'b': {...}}",
1174 \ "{'a': {'one': 'yes', 'two': 'yes', 'three': 'yes'}, 'b': {'one': 'yes', 'two': 'yes', 'three': 'yes'}}"], l)
1175
1176 " Lists in a list
1177 let a = [1, 2, 3]
1178 redir => result
1179 echo [a, a, a]
1180 echo string([a, a, a])
1181 redir END
1182 let l = split(result, "\n")
1183 call assert_equal(["[[1, 2, 3], [...], [...]]",
1184 \ "[[1, 2, 3], [1, 2, 3], [1, 2, 3]]"], l)
1185
1186 " Lists in a dictionary
1187 let a = [1, 2, 3]
1188 let b = {"a": a, "b": a}
1189 redir => result
1190 echo b
1191 echo string(b)
1192 redir END
1193 let l = split(result, "\n")
1194 call assert_equal(["{'a': [1, 2, 3], 'b': [...]}",
1195 \ "{'a': [1, 2, 3], 'b': [1, 2, 3]}"], l)
1196
1197 endfunc
1198
1199 "-------------------------------------------------------------------------------
1056 " Modelines {{{1 1200 " Modelines {{{1
1057 " vim: ts=8 sw=4 tw=80 fdm=marker 1201 " vim: ts=8 sw=4 tw=80 fdm=marker
1058 " vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "") 1202 " vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "")
1059 "------------------------------------------------------------------------------- 1203 "-------------------------------------------------------------------------------