z_all_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. // Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
  2. // Use of this source code is governed by a MIT license found in the LICENSE file.
  3. // +build alltests
  4. // +build go1.7
  5. package codec
  6. // Run this using:
  7. // go test -tags=alltests -run=Suite -coverprofile=cov.out
  8. // go tool cover -html=cov.out
  9. //
  10. // Because build tags are a build time parameter, we will have to test out the
  11. // different tags separately.
  12. // Tags: x codecgen safe appengine notfastpath
  13. //
  14. // These tags should be added to alltests, e.g.
  15. // go test '-tags=alltests x codecgen' -run=Suite -coverprofile=cov.out
  16. //
  17. // To run all tests before submitting code, run:
  18. // a=( "" "safe" "codecgen" "notfastpath" "codecgen notfastpath" "codecgen safe" "safe notfastpath" )
  19. // for i in "${a[@]}"; do echo ">>>> TAGS: $i"; go test "-tags=alltests $i" -run=Suite; done
  20. //
  21. // This only works on go1.7 and above. This is when subtests and suites were supported.
  22. import "testing"
  23. // func TestMain(m *testing.M) {
  24. // println("calling TestMain")
  25. // // set some parameters
  26. // exitcode := m.Run()
  27. // os.Exit(exitcode)
  28. // }
  29. func testGroupResetFlags() {
  30. testUseMust = false
  31. testCanonical = false
  32. testUseMust = false
  33. testInternStr = false
  34. testUseIoEncDec = -1
  35. testStructToArray = false
  36. testCheckCircRef = false
  37. testUseReset = false
  38. testMaxInitLen = 0
  39. testUseIoWrapper = false
  40. testNumRepeatString = 8
  41. testEncodeOptions.RecursiveEmptyCheck = false
  42. testDecodeOptions.MapValueReset = false
  43. testUseIoEncDec = -1
  44. testDepth = 0
  45. }
  46. func testSuite(t *testing.T, f func(t *testing.T)) {
  47. // find . -name "*_test.go" | xargs grep -e 'flag.' | cut -d '&' -f 2 | cut -d ',' -f 1 | grep -e '^test'
  48. // Disregard the following: testInitDebug, testSkipIntf, testJsonIndent (Need a test for it)
  49. testReinit() // so flag.Parse() is called first, and never called again
  50. testDecodeOptions = DecodeOptions{}
  51. testEncodeOptions = EncodeOptions{}
  52. testGroupResetFlags()
  53. testReinit()
  54. t.Run("optionsFalse", f)
  55. testCanonical = true
  56. testUseMust = true
  57. testInternStr = true
  58. testUseIoEncDec = 0
  59. testStructToArray = true
  60. testCheckCircRef = true
  61. testUseReset = true
  62. testDecodeOptions.MapValueReset = true
  63. testEncodeOptions.RecursiveEmptyCheck = true
  64. testReinit()
  65. t.Run("optionsTrue", f)
  66. testDepth = 6
  67. testReinit()
  68. t.Run("optionsTrue-deepstruct", f)
  69. testDepth = 0
  70. // testEncodeOptions.AsSymbols = AsSymbolAll
  71. testUseIoWrapper = true
  72. testReinit()
  73. t.Run("optionsTrue-ioWrapper", f)
  74. testUseIoEncDec = -1
  75. // make buffer small enough so that we have to re-fill multiple times.
  76. testSkipRPCTests = true
  77. testUseIoEncDec = 128
  78. // testDecodeOptions.ReaderBufferSize = 128
  79. // testEncodeOptions.WriterBufferSize = 128
  80. testReinit()
  81. t.Run("optionsTrue-bufio", f)
  82. // testDecodeOptions.ReaderBufferSize = 0
  83. // testEncodeOptions.WriterBufferSize = 0
  84. testUseIoEncDec = -1
  85. testSkipRPCTests = false
  86. testNumRepeatString = 32
  87. testReinit()
  88. t.Run("optionsTrue-largestrings", f)
  89. // The following here MUST be tested individually, as they create
  90. // side effects i.e. the decoded value is different.
  91. // testDecodeOptions.MapValueReset = true // ok - no side effects
  92. // testDecodeOptions.InterfaceReset = true // error??? because we do deepEquals to verify
  93. // testDecodeOptions.ErrorIfNoField = true // error, as expected, as fields not there
  94. // testDecodeOptions.ErrorIfNoArrayExpand = true // no error, but no error case either
  95. // testDecodeOptions.PreferArrayOverSlice = true // error??? because slice != array.
  96. // .... however, update deepEqual to take this option
  97. // testReinit()
  98. // t.Run("optionsTrue-resetOptions", f)
  99. testGroupResetFlags()
  100. }
  101. /*
  102. find . -name "codec_test.go" | xargs grep -e '^func Test' | \
  103. cut -d '(' -f 1 | cut -d ' ' -f 2 | \
  104. while read f; do echo "t.Run(\"$f\", $f)"; done
  105. */
  106. func testCodecGroup(t *testing.T) {
  107. // println("running testcodecsuite")
  108. // <setup code>
  109. t.Run("TestBincCodecsTable", TestBincCodecsTable)
  110. t.Run("TestBincCodecsMisc", TestBincCodecsMisc)
  111. t.Run("TestBincCodecsEmbeddedPointer", TestBincCodecsEmbeddedPointer)
  112. t.Run("TestBincStdEncIntf", TestBincStdEncIntf)
  113. t.Run("TestBincMammoth", TestBincMammoth)
  114. t.Run("TestSimpleCodecsTable", TestSimpleCodecsTable)
  115. t.Run("TestSimpleCodecsMisc", TestSimpleCodecsMisc)
  116. t.Run("TestSimpleCodecsEmbeddedPointer", TestSimpleCodecsEmbeddedPointer)
  117. t.Run("TestSimpleStdEncIntf", TestSimpleStdEncIntf)
  118. t.Run("TestSimpleMammoth", TestSimpleMammoth)
  119. t.Run("TestMsgpackCodecsTable", TestMsgpackCodecsTable)
  120. t.Run("TestMsgpackCodecsMisc", TestMsgpackCodecsMisc)
  121. t.Run("TestMsgpackCodecsEmbeddedPointer", TestMsgpackCodecsEmbeddedPointer)
  122. t.Run("TestMsgpackStdEncIntf", TestMsgpackStdEncIntf)
  123. t.Run("TestMsgpackMammoth", TestMsgpackMammoth)
  124. t.Run("TestCborCodecsTable", TestCborCodecsTable)
  125. t.Run("TestCborCodecsMisc", TestCborCodecsMisc)
  126. t.Run("TestCborCodecsEmbeddedPointer", TestCborCodecsEmbeddedPointer)
  127. t.Run("TestCborMapEncodeForCanonical", TestCborMapEncodeForCanonical)
  128. t.Run("TestCborCodecChan", TestCborCodecChan)
  129. t.Run("TestCborStdEncIntf", TestCborStdEncIntf)
  130. t.Run("TestCborMammoth", TestCborMammoth)
  131. t.Run("TestJsonCodecsTable", TestJsonCodecsTable)
  132. t.Run("TestJsonCodecsMisc", TestJsonCodecsMisc)
  133. t.Run("TestJsonCodecsEmbeddedPointer", TestJsonCodecsEmbeddedPointer)
  134. t.Run("TestJsonCodecChan", TestJsonCodecChan)
  135. t.Run("TestJsonStdEncIntf", TestJsonStdEncIntf)
  136. t.Run("TestJsonMammoth", TestJsonMammoth)
  137. t.Run("TestJsonRaw", TestJsonRaw)
  138. t.Run("TestBincRaw", TestBincRaw)
  139. t.Run("TestMsgpackRaw", TestMsgpackRaw)
  140. t.Run("TestSimpleRaw", TestSimpleRaw)
  141. t.Run("TestCborRaw", TestCborRaw)
  142. t.Run("TestAllEncCircularRef", TestAllEncCircularRef)
  143. t.Run("TestAllAnonCycle", TestAllAnonCycle)
  144. t.Run("TestBincRpcGo", TestBincRpcGo)
  145. t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
  146. t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
  147. t.Run("TestCborRpcGo", TestCborRpcGo)
  148. t.Run("TestJsonRpcGo", TestJsonRpcGo)
  149. t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
  150. t.Run("TestBincUnderlyingType", TestBincUnderlyingType)
  151. t.Run("TestJsonLargeInteger", TestJsonLargeInteger)
  152. t.Run("TestJsonDecodeNonStringScalarInStringContext", TestJsonDecodeNonStringScalarInStringContext)
  153. t.Run("TestJsonEncodeIndent", TestJsonEncodeIndent)
  154. t.Run("TestJsonSwallowAndZero", TestJsonSwallowAndZero)
  155. t.Run("TestCborSwallowAndZero", TestCborSwallowAndZero)
  156. t.Run("TestMsgpackSwallowAndZero", TestMsgpackSwallowAndZero)
  157. t.Run("TestBincSwallowAndZero", TestBincSwallowAndZero)
  158. t.Run("TestSimpleSwallowAndZero", TestSimpleSwallowAndZero)
  159. t.Run("TestJsonRawExt", TestJsonRawExt)
  160. t.Run("TestCborRawExt", TestCborRawExt)
  161. t.Run("TestMsgpackRawExt", TestMsgpackRawExt)
  162. t.Run("TestBincRawExt", TestBincRawExt)
  163. t.Run("TestSimpleRawExt", TestSimpleRawExt)
  164. t.Run("TestJsonMapStructKey", TestJsonMapStructKey)
  165. t.Run("TestCborMapStructKey", TestCborMapStructKey)
  166. t.Run("TestMsgpackMapStructKey", TestMsgpackMapStructKey)
  167. t.Run("TestBincMapStructKey", TestBincMapStructKey)
  168. t.Run("TestSimpleMapStructKey", TestSimpleMapStructKey)
  169. t.Run("TestJsonDecodeNilMapValue", TestJsonDecodeNilMapValue)
  170. t.Run("TestCborDecodeNilMapValue", TestCborDecodeNilMapValue)
  171. t.Run("TestMsgpackDecodeNilMapValue", TestMsgpackDecodeNilMapValue)
  172. t.Run("TestBincDecodeNilMapValue", TestBincDecodeNilMapValue)
  173. t.Run("TestSimpleDecodeNilMapValue", TestSimpleDecodeNilMapValue)
  174. t.Run("TestJsonEmbeddedFieldPrecedence", TestJsonEmbeddedFieldPrecedence)
  175. t.Run("TestCborEmbeddedFieldPrecedence", TestCborEmbeddedFieldPrecedence)
  176. t.Run("TestMsgpackEmbeddedFieldPrecedence", TestMsgpackEmbeddedFieldPrecedence)
  177. t.Run("TestBincEmbeddedFieldPrecedence", TestBincEmbeddedFieldPrecedence)
  178. t.Run("TestSimpleEmbeddedFieldPrecedence", TestSimpleEmbeddedFieldPrecedence)
  179. t.Run("TestJsonLargeContainerLen", TestJsonLargeContainerLen)
  180. t.Run("TestCborLargeContainerLen", TestCborLargeContainerLen)
  181. t.Run("TestMsgpackLargeContainerLen", TestMsgpackLargeContainerLen)
  182. t.Run("TestBincLargeContainerLen", TestBincLargeContainerLen)
  183. t.Run("TestSimpleLargeContainerLen", TestSimpleLargeContainerLen)
  184. t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices)
  185. t.Run("TestCborMammothMapsAndSlices", TestCborMammothMapsAndSlices)
  186. t.Run("TestMsgpackMammothMapsAndSlices", TestMsgpackMammothMapsAndSlices)
  187. t.Run("TestBincMammothMapsAndSlices", TestBincMammothMapsAndSlices)
  188. t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices)
  189. t.Run("TestJsonTime", TestJsonTime)
  190. t.Run("TestCborTime", TestCborTime)
  191. t.Run("TestMsgpackTime", TestMsgpackTime)
  192. t.Run("TestBincTime", TestBincTime)
  193. t.Run("TestSimpleTime", TestSimpleTime)
  194. t.Run("TestJsonUintToInt", TestJsonUintToInt)
  195. t.Run("TestCborUintToInt", TestCborUintToInt)
  196. t.Run("TestMsgpackUintToInt", TestMsgpackUintToInt)
  197. t.Run("TestBincUintToInt", TestBincUintToInt)
  198. t.Run("TestSimpleUintToInt", TestSimpleUintToInt)
  199. t.Run("TestJsonDifferentMapOrSliceType", TestJsonDifferentMapOrSliceType)
  200. t.Run("TestCborDifferentMapOrSliceType", TestCborDifferentMapOrSliceType)
  201. t.Run("TestMsgpackDifferentMapOrSliceType", TestMsgpackDifferentMapOrSliceType)
  202. t.Run("TestBincDifferentMapOrSliceType", TestBincDifferentMapOrSliceType)
  203. t.Run("TestSimpleDifferentMapOrSliceType", TestSimpleDifferentMapOrSliceType)
  204. t.Run("TestJsonScalars", TestJsonScalars)
  205. t.Run("TestCborScalars", TestCborScalars)
  206. t.Run("TestMsgpackScalars", TestMsgpackScalars)
  207. t.Run("TestBincScalars", TestBincScalars)
  208. t.Run("TestSimpleScalars", TestSimpleScalars)
  209. t.Run("TestJsonInvalidUnicode", TestJsonInvalidUnicode)
  210. t.Run("TestCborHalfFloat", TestCborHalfFloat)
  211. // <tear-down code>
  212. }
  213. func testJsonGroup(t *testing.T) {
  214. t.Run("TestJsonCodecsTable", TestJsonCodecsTable)
  215. t.Run("TestJsonCodecsMisc", TestJsonCodecsMisc)
  216. t.Run("TestJsonCodecsEmbeddedPointer", TestJsonCodecsEmbeddedPointer)
  217. t.Run("TestJsonCodecChan", TestJsonCodecChan)
  218. t.Run("TestJsonStdEncIntf", TestJsonStdEncIntf)
  219. t.Run("TestJsonMammoth", TestJsonMammoth)
  220. t.Run("TestJsonRaw", TestJsonRaw)
  221. t.Run("TestJsonRpcGo", TestJsonRpcGo)
  222. t.Run("TestJsonLargeInteger", TestJsonLargeInteger)
  223. t.Run("TestJsonDecodeNonStringScalarInStringContext", TestJsonDecodeNonStringScalarInStringContext)
  224. t.Run("TestJsonEncodeIndent", TestJsonEncodeIndent)
  225. t.Run("TestJsonSwallowAndZero", TestJsonSwallowAndZero)
  226. t.Run("TestJsonRawExt", TestJsonRawExt)
  227. t.Run("TestJsonMapStructKey", TestJsonMapStructKey)
  228. t.Run("TestJsonDecodeNilMapValue", TestJsonDecodeNilMapValue)
  229. t.Run("TestJsonEmbeddedFieldPrecedence", TestJsonEmbeddedFieldPrecedence)
  230. t.Run("TestJsonLargeContainerLen", TestJsonLargeContainerLen)
  231. t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices)
  232. t.Run("TestJsonInvalidUnicode", TestJsonInvalidUnicode)
  233. t.Run("TestJsonTime", TestJsonTime)
  234. t.Run("TestJsonUintToInt", TestJsonUintToInt)
  235. t.Run("TestJsonDifferentMapOrSliceType", TestJsonDifferentMapOrSliceType)
  236. t.Run("TestJsonScalars", TestJsonScalars)
  237. }
  238. func testBincGroup(t *testing.T) {
  239. t.Run("TestBincCodecsTable", TestBincCodecsTable)
  240. t.Run("TestBincCodecsMisc", TestBincCodecsMisc)
  241. t.Run("TestBincCodecsEmbeddedPointer", TestBincCodecsEmbeddedPointer)
  242. t.Run("TestBincStdEncIntf", TestBincStdEncIntf)
  243. t.Run("TestBincMammoth", TestBincMammoth)
  244. t.Run("TestBincRaw", TestBincRaw)
  245. t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
  246. t.Run("TestBincUnderlyingType", TestBincUnderlyingType)
  247. t.Run("TestBincSwallowAndZero", TestBincSwallowAndZero)
  248. t.Run("TestBincRawExt", TestBincRawExt)
  249. t.Run("TestBincMapStructKey", TestBincMapStructKey)
  250. t.Run("TestBincDecodeNilMapValue", TestBincDecodeNilMapValue)
  251. t.Run("TestBincEmbeddedFieldPrecedence", TestBincEmbeddedFieldPrecedence)
  252. t.Run("TestBincLargeContainerLen", TestBincLargeContainerLen)
  253. t.Run("TestBincMammothMapsAndSlices", TestBincMammothMapsAndSlices)
  254. t.Run("TestBincTime", TestBincTime)
  255. t.Run("TestBincUintToInt", TestBincUintToInt)
  256. t.Run("TestBincDifferentMapOrSliceType", TestBincDifferentMapOrSliceType)
  257. t.Run("TestBincScalars", TestBincScalars)
  258. }
  259. func testCborGroup(t *testing.T) {
  260. t.Run("TestCborCodecsTable", TestCborCodecsTable)
  261. t.Run("TestCborCodecsMisc", TestCborCodecsMisc)
  262. t.Run("TestCborCodecsEmbeddedPointer", TestCborCodecsEmbeddedPointer)
  263. t.Run("TestCborMapEncodeForCanonical", TestCborMapEncodeForCanonical)
  264. t.Run("TestCborCodecChan", TestCborCodecChan)
  265. t.Run("TestCborStdEncIntf", TestCborStdEncIntf)
  266. t.Run("TestCborMammoth", TestCborMammoth)
  267. t.Run("TestCborRaw", TestCborRaw)
  268. t.Run("TestCborRpcGo", TestCborRpcGo)
  269. t.Run("TestCborSwallowAndZero", TestCborSwallowAndZero)
  270. t.Run("TestCborRawExt", TestCborRawExt)
  271. t.Run("TestCborMapStructKey", TestCborMapStructKey)
  272. t.Run("TestCborDecodeNilMapValue", TestCborDecodeNilMapValue)
  273. t.Run("TestCborEmbeddedFieldPrecedence", TestCborEmbeddedFieldPrecedence)
  274. t.Run("TestCborLargeContainerLen", TestCborLargeContainerLen)
  275. t.Run("TestCborMammothMapsAndSlices", TestCborMammothMapsAndSlices)
  276. t.Run("TestCborTime", TestCborTime)
  277. t.Run("TestCborUintToInt", TestCborUintToInt)
  278. t.Run("TestCborDifferentMapOrSliceType", TestCborDifferentMapOrSliceType)
  279. t.Run("TestCborScalars", TestCborScalars)
  280. t.Run("TestCborHalfFloat", TestCborHalfFloat)
  281. }
  282. func testMsgpackGroup(t *testing.T) {
  283. t.Run("TestMsgpackCodecsTable", TestMsgpackCodecsTable)
  284. t.Run("TestMsgpackCodecsMisc", TestMsgpackCodecsMisc)
  285. t.Run("TestMsgpackCodecsEmbeddedPointer", TestMsgpackCodecsEmbeddedPointer)
  286. t.Run("TestMsgpackStdEncIntf", TestMsgpackStdEncIntf)
  287. t.Run("TestMsgpackMammoth", TestMsgpackMammoth)
  288. t.Run("TestMsgpackRaw", TestMsgpackRaw)
  289. t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
  290. t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
  291. t.Run("TestMsgpackSwallowAndZero", TestMsgpackSwallowAndZero)
  292. t.Run("TestMsgpackRawExt", TestMsgpackRawExt)
  293. t.Run("TestMsgpackMapStructKey", TestMsgpackMapStructKey)
  294. t.Run("TestMsgpackDecodeNilMapValue", TestMsgpackDecodeNilMapValue)
  295. t.Run("TestMsgpackEmbeddedFieldPrecedence", TestMsgpackEmbeddedFieldPrecedence)
  296. t.Run("TestMsgpackLargeContainerLen", TestMsgpackLargeContainerLen)
  297. t.Run("TestMsgpackMammothMapsAndSlices", TestMsgpackMammothMapsAndSlices)
  298. t.Run("TestMsgpackTime", TestMsgpackTime)
  299. t.Run("TestMsgpackUintToInt", TestMsgpackUintToInt)
  300. t.Run("TestMsgpackDifferentMapOrSliceType", TestMsgpackDifferentMapOrSliceType)
  301. t.Run("TestMsgpackScalars", TestMsgpackScalars)
  302. }
  303. func testSimpleGroup(t *testing.T) {
  304. t.Run("TestSimpleCodecsTable", TestSimpleCodecsTable)
  305. t.Run("TestSimpleCodecsMisc", TestSimpleCodecsMisc)
  306. t.Run("TestSimpleCodecsEmbeddedPointer", TestSimpleCodecsEmbeddedPointer)
  307. t.Run("TestSimpleStdEncIntf", TestSimpleStdEncIntf)
  308. t.Run("TestSimpleMammoth", TestSimpleMammoth)
  309. t.Run("TestSimpleRaw", TestSimpleRaw)
  310. t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
  311. t.Run("TestSimpleSwallowAndZero", TestSimpleSwallowAndZero)
  312. t.Run("TestSimpleRawExt", TestSimpleRawExt)
  313. t.Run("TestSimpleMapStructKey", TestSimpleMapStructKey)
  314. t.Run("TestSimpleDecodeNilMapValue", TestSimpleDecodeNilMapValue)
  315. t.Run("TestSimpleEmbeddedFieldPrecedence", TestSimpleEmbeddedFieldPrecedence)
  316. t.Run("TestSimpleLargeContainerLen", TestSimpleLargeContainerLen)
  317. t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices)
  318. t.Run("TestSimpleTime", TestSimpleTime)
  319. t.Run("TestSimpleUintToInt", TestSimpleUintToInt)
  320. t.Run("TestSimpleDifferentMapOrSliceType", TestSimpleDifferentMapOrSliceType)
  321. t.Run("TestSimpleScalars", TestSimpleScalars)
  322. }
  323. func testSimpleMammothGroup(t *testing.T) {
  324. t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices)
  325. }
  326. func testRpcGroup(t *testing.T) {
  327. t.Run("TestBincRpcGo", TestBincRpcGo)
  328. t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
  329. t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
  330. t.Run("TestCborRpcGo", TestCborRpcGo)
  331. t.Run("TestJsonRpcGo", TestJsonRpcGo)
  332. t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
  333. }
  334. func TestCodecSuite(t *testing.T) {
  335. testSuite(t, testCodecGroup)
  336. testGroupResetFlags()
  337. oldIndent, oldCharsAsis, oldPreferFloat, oldMapKeyAsString :=
  338. testJsonH.Indent, testJsonH.HTMLCharsAsIs, testJsonH.PreferFloat, testJsonH.MapKeyAsString
  339. testMaxInitLen = 10
  340. testJsonH.Indent = 8
  341. testJsonH.HTMLCharsAsIs = true
  342. testJsonH.MapKeyAsString = true
  343. // testJsonH.PreferFloat = true
  344. testReinit()
  345. t.Run("json-spaces-htmlcharsasis-initLen10", testJsonGroup)
  346. testMaxInitLen = 10
  347. testJsonH.Indent = -1
  348. testJsonH.HTMLCharsAsIs = false
  349. testJsonH.MapKeyAsString = true
  350. // testJsonH.PreferFloat = false
  351. testReinit()
  352. t.Run("json-tabs-initLen10", testJsonGroup)
  353. testJsonH.Indent, testJsonH.HTMLCharsAsIs, testJsonH.PreferFloat, testJsonH.MapKeyAsString =
  354. oldIndent, oldCharsAsis, oldPreferFloat, oldMapKeyAsString
  355. oldIndefLen := testCborH.IndefiniteLength
  356. testCborH.IndefiniteLength = true
  357. testReinit()
  358. t.Run("cbor-indefinitelength", testCborGroup)
  359. testCborH.IndefiniteLength = oldIndefLen
  360. oldTimeRFC3339 := testCborH.TimeRFC3339
  361. testCborH.TimeRFC3339 = !testCborH.TimeRFC3339
  362. testReinit()
  363. t.Run("cbor-rfc3339", testCborGroup)
  364. testCborH.TimeRFC3339 = oldTimeRFC3339
  365. oldSymbols := testBincH.AsSymbols
  366. testBincH.AsSymbols = 2 // AsSymbolNone
  367. testReinit()
  368. t.Run("binc-no-symbols", testBincGroup)
  369. testBincH.AsSymbols = 1 // AsSymbolAll
  370. testReinit()
  371. t.Run("binc-all-symbols", testBincGroup)
  372. testBincH.AsSymbols = oldSymbols
  373. oldWriteExt := testMsgpackH.WriteExt
  374. oldNoFixedNum := testMsgpackH.NoFixedNum
  375. testMsgpackH.WriteExt = !testMsgpackH.WriteExt
  376. testReinit()
  377. t.Run("msgpack-inverse-writeext", testMsgpackGroup)
  378. testMsgpackH.WriteExt = oldWriteExt
  379. testMsgpackH.NoFixedNum = !testMsgpackH.NoFixedNum
  380. testReinit()
  381. t.Run("msgpack-fixednum", testMsgpackGroup)
  382. testMsgpackH.NoFixedNum = oldNoFixedNum
  383. oldEncZeroValuesAsNil := testSimpleH.EncZeroValuesAsNil
  384. testSimpleH.EncZeroValuesAsNil = !testSimpleH.EncZeroValuesAsNil
  385. testUseMust = true
  386. testReinit()
  387. t.Run("simple-enczeroasnil", testSimpleMammothGroup) // testSimpleGroup
  388. testSimpleH.EncZeroValuesAsNil = oldEncZeroValuesAsNil
  389. oldRpcBufsize := testRpcBufsize
  390. testRpcBufsize = 0
  391. t.Run("rpc-buf-0", testRpcGroup)
  392. testRpcBufsize = 0
  393. t.Run("rpc-buf-00", testRpcGroup)
  394. testRpcBufsize = 0
  395. t.Run("rpc-buf-000", testRpcGroup)
  396. testRpcBufsize = 16
  397. t.Run("rpc-buf-16", testRpcGroup)
  398. testRpcBufsize = 2048
  399. t.Run("rpc-buf-2048", testRpcGroup)
  400. testRpcBufsize = oldRpcBufsize
  401. testGroupResetFlags()
  402. }
  403. // func TestCodecSuite(t *testing.T) {
  404. // testReinit() // so flag.Parse() is called first, and never called again
  405. // testDecodeOptions, testEncodeOptions = DecodeOptions{}, EncodeOptions{}
  406. // testGroupResetFlags()
  407. // testReinit()
  408. // t.Run("optionsFalse", func(t *testing.T) {
  409. // t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices)
  410. // })
  411. // }