z_all_test.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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("TestJsonOmitempty", TestJsonOmitempty)
  210. t.Run("TestCborOmitempty", TestCborOmitempty)
  211. t.Run("TestMsgpackOmitempty", TestMsgpackOmitempty)
  212. t.Run("TestBincOmitempty", TestBincOmitempty)
  213. t.Run("TestSimpleOmitempty", TestSimpleOmitempty)
  214. t.Run("TestJsonIntfMapping", TestJsonIntfMapping)
  215. t.Run("TestCborIntfMapping", TestCborIntfMapping)
  216. t.Run("TestMsgpackIntfMapping", TestMsgpackIntfMapping)
  217. t.Run("TestBincIntfMapping", TestBincIntfMapping)
  218. t.Run("TestSimpleIntfMapping", TestSimpleIntfMapping)
  219. t.Run("TestJsonMissingFields", TestJsonMissingFields)
  220. t.Run("TestCborMissingFields", TestCborMissingFields)
  221. t.Run("TestMsgpackMissingFields", TestMsgpackMissingFields)
  222. t.Run("TestBincMissingFields", TestBincMissingFields)
  223. t.Run("TestSimpleMissingFields", TestSimpleMissingFields)
  224. t.Run("TestJsonMaxDepth", TestJsonMaxDepth)
  225. t.Run("TestCborMaxDepth", TestCborMaxDepth)
  226. t.Run("TestMsgpackMaxDepth", TestMsgpackMaxDepth)
  227. t.Run("TestBincMaxDepth", TestBincMaxDepth)
  228. t.Run("TestSimpleMaxDepth", TestSimpleMaxDepth)
  229. t.Run("TestJsonInvalidUnicode", TestJsonInvalidUnicode)
  230. t.Run("TestCborHalfFloat", TestCborHalfFloat)
  231. t.Run("TestMsgpackDecodeMapAndExtSizeMismatch", TestMsgpackDecodeMapAndExtSizeMismatch)
  232. // <tear-down code>
  233. }
  234. func testJsonGroup(t *testing.T) {
  235. t.Run("TestJsonCodecsTable", TestJsonCodecsTable)
  236. t.Run("TestJsonCodecsMisc", TestJsonCodecsMisc)
  237. t.Run("TestJsonCodecsEmbeddedPointer", TestJsonCodecsEmbeddedPointer)
  238. t.Run("TestJsonCodecChan", TestJsonCodecChan)
  239. t.Run("TestJsonStdEncIntf", TestJsonStdEncIntf)
  240. t.Run("TestJsonMammoth", TestJsonMammoth)
  241. t.Run("TestJsonRaw", TestJsonRaw)
  242. t.Run("TestJsonRpcGo", TestJsonRpcGo)
  243. t.Run("TestJsonLargeInteger", TestJsonLargeInteger)
  244. t.Run("TestJsonDecodeNonStringScalarInStringContext", TestJsonDecodeNonStringScalarInStringContext)
  245. t.Run("TestJsonEncodeIndent", TestJsonEncodeIndent)
  246. t.Run("TestJsonSwallowAndZero", TestJsonSwallowAndZero)
  247. t.Run("TestJsonRawExt", TestJsonRawExt)
  248. t.Run("TestJsonMapStructKey", TestJsonMapStructKey)
  249. t.Run("TestJsonDecodeNilMapValue", TestJsonDecodeNilMapValue)
  250. t.Run("TestJsonEmbeddedFieldPrecedence", TestJsonEmbeddedFieldPrecedence)
  251. t.Run("TestJsonLargeContainerLen", TestJsonLargeContainerLen)
  252. t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices)
  253. t.Run("TestJsonTime", TestJsonTime)
  254. t.Run("TestJsonUintToInt", TestJsonUintToInt)
  255. t.Run("TestJsonDifferentMapOrSliceType", TestJsonDifferentMapOrSliceType)
  256. t.Run("TestJsonScalars", TestJsonScalars)
  257. t.Run("TestJsonOmitempty", TestJsonOmitempty)
  258. t.Run("TestJsonIntfMapping", TestJsonIntfMapping)
  259. t.Run("TestJsonMissingFields", TestJsonMissingFields)
  260. t.Run("TestJsonMaxDepth", TestJsonMaxDepth)
  261. t.Run("TestJsonInvalidUnicode", TestJsonInvalidUnicode)
  262. }
  263. func testBincGroup(t *testing.T) {
  264. t.Run("TestBincCodecsTable", TestBincCodecsTable)
  265. t.Run("TestBincCodecsMisc", TestBincCodecsMisc)
  266. t.Run("TestBincCodecsEmbeddedPointer", TestBincCodecsEmbeddedPointer)
  267. t.Run("TestBincStdEncIntf", TestBincStdEncIntf)
  268. t.Run("TestBincMammoth", TestBincMammoth)
  269. t.Run("TestBincRaw", TestBincRaw)
  270. t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
  271. t.Run("TestBincUnderlyingType", TestBincUnderlyingType)
  272. t.Run("TestBincSwallowAndZero", TestBincSwallowAndZero)
  273. t.Run("TestBincRawExt", TestBincRawExt)
  274. t.Run("TestBincMapStructKey", TestBincMapStructKey)
  275. t.Run("TestBincDecodeNilMapValue", TestBincDecodeNilMapValue)
  276. t.Run("TestBincEmbeddedFieldPrecedence", TestBincEmbeddedFieldPrecedence)
  277. t.Run("TestBincLargeContainerLen", TestBincLargeContainerLen)
  278. t.Run("TestBincMammothMapsAndSlices", TestBincMammothMapsAndSlices)
  279. t.Run("TestBincTime", TestBincTime)
  280. t.Run("TestBincUintToInt", TestBincUintToInt)
  281. t.Run("TestBincDifferentMapOrSliceType", TestBincDifferentMapOrSliceType)
  282. t.Run("TestBincScalars", TestBincScalars)
  283. t.Run("TestBincOmitempty", TestBincOmitempty)
  284. t.Run("TestBincIntfMapping", TestBincIntfMapping)
  285. t.Run("TestBincMissingFields", TestBincMissingFields)
  286. t.Run("TestBincMaxDepth", TestBincMaxDepth)
  287. }
  288. func testCborGroup(t *testing.T) {
  289. t.Run("TestCborCodecsTable", TestCborCodecsTable)
  290. t.Run("TestCborCodecsMisc", TestCborCodecsMisc)
  291. t.Run("TestCborCodecsEmbeddedPointer", TestCborCodecsEmbeddedPointer)
  292. t.Run("TestCborMapEncodeForCanonical", TestCborMapEncodeForCanonical)
  293. t.Run("TestCborCodecChan", TestCborCodecChan)
  294. t.Run("TestCborStdEncIntf", TestCborStdEncIntf)
  295. t.Run("TestCborMammoth", TestCborMammoth)
  296. t.Run("TestCborRaw", TestCborRaw)
  297. t.Run("TestCborRpcGo", TestCborRpcGo)
  298. t.Run("TestCborSwallowAndZero", TestCborSwallowAndZero)
  299. t.Run("TestCborRawExt", TestCborRawExt)
  300. t.Run("TestCborMapStructKey", TestCborMapStructKey)
  301. t.Run("TestCborDecodeNilMapValue", TestCborDecodeNilMapValue)
  302. t.Run("TestCborEmbeddedFieldPrecedence", TestCborEmbeddedFieldPrecedence)
  303. t.Run("TestCborLargeContainerLen", TestCborLargeContainerLen)
  304. t.Run("TestCborMammothMapsAndSlices", TestCborMammothMapsAndSlices)
  305. t.Run("TestCborTime", TestCborTime)
  306. t.Run("TestCborUintToInt", TestCborUintToInt)
  307. t.Run("TestCborDifferentMapOrSliceType", TestCborDifferentMapOrSliceType)
  308. t.Run("TestCborScalars", TestCborScalars)
  309. t.Run("TestCborOmitempty", TestCborOmitempty)
  310. t.Run("TestCborIntfMapping", TestCborIntfMapping)
  311. t.Run("TestCborMissingFields", TestCborMissingFields)
  312. t.Run("TestCborMaxDepth", TestCborMaxDepth)
  313. t.Run("TestCborHalfFloat", TestCborHalfFloat)
  314. }
  315. func testMsgpackGroup(t *testing.T) {
  316. t.Run("TestMsgpackCodecsTable", TestMsgpackCodecsTable)
  317. t.Run("TestMsgpackCodecsMisc", TestMsgpackCodecsMisc)
  318. t.Run("TestMsgpackCodecsEmbeddedPointer", TestMsgpackCodecsEmbeddedPointer)
  319. t.Run("TestMsgpackStdEncIntf", TestMsgpackStdEncIntf)
  320. t.Run("TestMsgpackMammoth", TestMsgpackMammoth)
  321. t.Run("TestMsgpackRaw", TestMsgpackRaw)
  322. t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
  323. t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
  324. t.Run("TestMsgpackSwallowAndZero", TestMsgpackSwallowAndZero)
  325. t.Run("TestMsgpackRawExt", TestMsgpackRawExt)
  326. t.Run("TestMsgpackMapStructKey", TestMsgpackMapStructKey)
  327. t.Run("TestMsgpackDecodeNilMapValue", TestMsgpackDecodeNilMapValue)
  328. t.Run("TestMsgpackEmbeddedFieldPrecedence", TestMsgpackEmbeddedFieldPrecedence)
  329. t.Run("TestMsgpackLargeContainerLen", TestMsgpackLargeContainerLen)
  330. t.Run("TestMsgpackMammothMapsAndSlices", TestMsgpackMammothMapsAndSlices)
  331. t.Run("TestMsgpackTime", TestMsgpackTime)
  332. t.Run("TestMsgpackUintToInt", TestMsgpackUintToInt)
  333. t.Run("TestMsgpackDifferentMapOrSliceType", TestMsgpackDifferentMapOrSliceType)
  334. t.Run("TestMsgpackScalars", TestMsgpackScalars)
  335. t.Run("TestMsgpackOmitempty", TestMsgpackOmitempty)
  336. t.Run("TestMsgpackIntfMapping", TestMsgpackIntfMapping)
  337. t.Run("TestMsgpackMissingFields", TestMsgpackMissingFields)
  338. t.Run("TestMsgpackMaxDepth", TestMsgpackMaxDepth)
  339. t.Run("TestMsgpackDecodeMapAndExtSizeMismatch", TestMsgpackDecodeMapAndExtSizeMismatch)
  340. }
  341. func testSimpleGroup(t *testing.T) {
  342. t.Run("TestSimpleCodecsTable", TestSimpleCodecsTable)
  343. t.Run("TestSimpleCodecsMisc", TestSimpleCodecsMisc)
  344. t.Run("TestSimpleCodecsEmbeddedPointer", TestSimpleCodecsEmbeddedPointer)
  345. t.Run("TestSimpleStdEncIntf", TestSimpleStdEncIntf)
  346. t.Run("TestSimpleMammoth", TestSimpleMammoth)
  347. t.Run("TestSimpleRaw", TestSimpleRaw)
  348. t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
  349. t.Run("TestSimpleSwallowAndZero", TestSimpleSwallowAndZero)
  350. t.Run("TestSimpleRawExt", TestSimpleRawExt)
  351. t.Run("TestSimpleMapStructKey", TestSimpleMapStructKey)
  352. t.Run("TestSimpleDecodeNilMapValue", TestSimpleDecodeNilMapValue)
  353. t.Run("TestSimpleEmbeddedFieldPrecedence", TestSimpleEmbeddedFieldPrecedence)
  354. t.Run("TestSimpleLargeContainerLen", TestSimpleLargeContainerLen)
  355. t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices)
  356. t.Run("TestSimpleTime", TestSimpleTime)
  357. t.Run("TestSimpleUintToInt", TestSimpleUintToInt)
  358. t.Run("TestSimpleDifferentMapOrSliceType", TestSimpleDifferentMapOrSliceType)
  359. t.Run("TestSimpleScalars", TestSimpleScalars)
  360. t.Run("TestSimpleOmitempty", TestSimpleOmitempty)
  361. t.Run("TestSimpleIntfMapping", TestSimpleIntfMapping)
  362. t.Run("TestSimpleMissingFields", TestSimpleMissingFields)
  363. t.Run("TestSimpleMaxDepth", TestSimpleMaxDepth)
  364. }
  365. func testSimpleMammothGroup(t *testing.T) {
  366. t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices)
  367. }
  368. func testRpcGroup(t *testing.T) {
  369. t.Run("TestBincRpcGo", TestBincRpcGo)
  370. t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
  371. t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
  372. t.Run("TestCborRpcGo", TestCborRpcGo)
  373. t.Run("TestJsonRpcGo", TestJsonRpcGo)
  374. t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
  375. }
  376. func TestCodecSuite(t *testing.T) {
  377. testSuite(t, testCodecGroup)
  378. testGroupResetFlags()
  379. oldIndent, oldCharsAsis, oldPreferFloat, oldMapKeyAsString :=
  380. testJsonH.Indent, testJsonH.HTMLCharsAsIs, testJsonH.PreferFloat, testJsonH.MapKeyAsString
  381. testMaxInitLen = 10
  382. testJsonH.Indent = 8
  383. testJsonH.HTMLCharsAsIs = true
  384. testJsonH.MapKeyAsString = true
  385. // testJsonH.PreferFloat = true
  386. testReinit()
  387. t.Run("json-spaces-htmlcharsasis-initLen10", testJsonGroup)
  388. testMaxInitLen = 10
  389. testJsonH.Indent = -1
  390. testJsonH.HTMLCharsAsIs = false
  391. testJsonH.MapKeyAsString = true
  392. // testJsonH.PreferFloat = false
  393. testReinit()
  394. t.Run("json-tabs-initLen10", testJsonGroup)
  395. testJsonH.Indent, testJsonH.HTMLCharsAsIs, testJsonH.PreferFloat, testJsonH.MapKeyAsString =
  396. oldIndent, oldCharsAsis, oldPreferFloat, oldMapKeyAsString
  397. oldIndefLen := testCborH.IndefiniteLength
  398. testCborH.IndefiniteLength = true
  399. testReinit()
  400. t.Run("cbor-indefinitelength", testCborGroup)
  401. testCborH.IndefiniteLength = oldIndefLen
  402. oldTimeRFC3339 := testCborH.TimeRFC3339
  403. testCborH.TimeRFC3339 = !testCborH.TimeRFC3339
  404. testReinit()
  405. t.Run("cbor-rfc3339", testCborGroup)
  406. testCborH.TimeRFC3339 = oldTimeRFC3339
  407. oldSymbols := testBincH.AsSymbols
  408. testBincH.AsSymbols = 2 // AsSymbolNone
  409. testReinit()
  410. t.Run("binc-no-symbols", testBincGroup)
  411. testBincH.AsSymbols = 1 // AsSymbolAll
  412. testReinit()
  413. t.Run("binc-all-symbols", testBincGroup)
  414. testBincH.AsSymbols = oldSymbols
  415. oldWriteExt := testMsgpackH.WriteExt
  416. oldNoFixedNum := testMsgpackH.NoFixedNum
  417. testMsgpackH.WriteExt = !testMsgpackH.WriteExt
  418. testReinit()
  419. t.Run("msgpack-inverse-writeext", testMsgpackGroup)
  420. testMsgpackH.WriteExt = oldWriteExt
  421. testMsgpackH.NoFixedNum = !testMsgpackH.NoFixedNum
  422. testReinit()
  423. t.Run("msgpack-fixednum", testMsgpackGroup)
  424. testMsgpackH.NoFixedNum = oldNoFixedNum
  425. oldEncZeroValuesAsNil := testSimpleH.EncZeroValuesAsNil
  426. testSimpleH.EncZeroValuesAsNil = !testSimpleH.EncZeroValuesAsNil
  427. testUseMust = true
  428. testReinit()
  429. t.Run("simple-enczeroasnil", testSimpleMammothGroup) // testSimpleGroup
  430. testSimpleH.EncZeroValuesAsNil = oldEncZeroValuesAsNil
  431. oldRpcBufsize := testRpcBufsize
  432. testRpcBufsize = 0
  433. t.Run("rpc-buf-0", testRpcGroup)
  434. testRpcBufsize = 0
  435. t.Run("rpc-buf-00", testRpcGroup)
  436. testRpcBufsize = 0
  437. t.Run("rpc-buf-000", testRpcGroup)
  438. testRpcBufsize = 16
  439. t.Run("rpc-buf-16", testRpcGroup)
  440. testRpcBufsize = 2048
  441. t.Run("rpc-buf-2048", testRpcGroup)
  442. testRpcBufsize = oldRpcBufsize
  443. testGroupResetFlags()
  444. }
  445. // func TestCodecSuite(t *testing.T) {
  446. // testReinit() // so flag.Parse() is called first, and never called again
  447. // testDecodeOptions, testEncodeOptions = DecodeOptions{}, EncodeOptions{}
  448. // testGroupResetFlags()
  449. // testReinit()
  450. // t.Run("optionsFalse", func(t *testing.T) {
  451. // t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices)
  452. // })
  453. // }