James E. King, III | 375bfee | 2017-10-26 00:09:34 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 20 | "use strict"; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 21 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 22 | import helpers from "./helpers.js"; |
| 23 | import Int64 from "node-int64"; |
| 24 | |
| 25 | const ttypes = await helpers.importTypes(`ThriftTest_types`); |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 26 | |
| 27 | //all Languages in UTF-8 |
| 28 | /*jshint -W100 */ |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 29 | export const stringTest = |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 30 | "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " + |
| 31 | "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " + |
| 32 | "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " + |
| 33 | "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " + |
| 34 | "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " + |
| 35 | "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " + |
| 36 | "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " + |
| 37 | "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " + |
| 38 | "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " + |
| 39 | "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " + |
| 40 | "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " + |
| 41 | "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " + |
| 42 | "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " + |
| 43 | "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " + |
| 44 | "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " + |
| 45 | "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, " + |
| 46 | "Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, " + |
| 47 | "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " + |
| 48 | "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " + |
| 49 | "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " + |
| 50 | "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " + |
| 51 | "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " + |
| 52 | "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " + |
| 53 | "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " + |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 54 | "Bân-lâm-gú, 粵語"; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 55 | /*jshint +W100 */ |
| 56 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 57 | export const specialCharacters = |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 58 | 'quote: " backslash:' + |
| 59 | " forwardslash-escaped: / " + |
| 60 | " backspace: \b formfeed: \f newline: \n return: \r tab: " + |
| 61 | ' now-all-of-them-together: "\\/\b\n\r\t' + |
| 62 | " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><" + |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 63 | ' char-to-test-json-parsing: ]] "]] \\" }}}{ [[[ '; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 64 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 65 | export const mapTestInput = { |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 66 | a: "123", |
| 67 | "a b": "with spaces ", |
| 68 | same: "same", |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 69 | 0: "numeric key", |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 70 | longValue: stringTest, |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 71 | stringTest: "long key", |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 72 | }; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 73 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 74 | export const simple = [ |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 75 | ["testVoid", undefined], |
| 76 | ["testString", "Test"], |
| 77 | ["testString", ""], |
| 78 | ["testString", stringTest], |
| 79 | ["testString", specialCharacters], |
| 80 | ["testBool", true], |
| 81 | ["testBool", false], |
| 82 | ["testByte", 1], |
| 83 | ["testByte", 0], |
| 84 | ["testByte", -1], |
| 85 | ["testByte", -127], |
| 86 | ["testI32", -1], |
| 87 | ["testDouble", -5.2098523], |
| 88 | ["testDouble", 7.012052175215044], |
| 89 | ["testEnum", ttypes.Numberz.ONE], |
| 90 | ["testI64", 5], |
| 91 | ["testI64", -5], |
| 92 | ["testI64", 734359738368], |
| 93 | ["testI64", -734359738368], |
| 94 | ["testI64", new Int64(new Buffer([0, 0x20, 0, 0, 0, 0, 0, 1]))], // 2^53+1 |
| 95 | [ |
| 96 | "testI64", |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 97 | new Int64(new Buffer([0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])), |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 98 | ], // -2^53-1 |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 99 | ["testTypedef", 69], |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 100 | ]; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 101 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 102 | const mapout = {}; |
| 103 | for (let i = 0; i < 5; ++i) { |
| 104 | mapout[i] = i - 10; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 107 | export const deep = [ |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 108 | [ |
| 109 | "testList", |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 110 | [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], |
| 111 | ], |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 112 | ]; |
| 113 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 114 | export const deepUnordered = [ |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 115 | ["testMap", mapout], |
| 116 | ["testSet", [1, 2, 3]], |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 117 | ["testStringMap", mapTestInput], |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 118 | ]; |
| 119 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 120 | export const out = new ttypes.Xtruct({ |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 121 | string_thing: "Zero", |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 122 | byte_thing: 1, |
| 123 | i32_thing: -3, |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 124 | i64_thing: 1000000, |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 125 | }); |
| 126 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 127 | export const out2 = new ttypes.Xtruct2(); |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 128 | out2.byte_thing = 1; |
| 129 | out2.struct_thing = out; |
| 130 | out2.i32_thing = 5; |
| 131 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 132 | export const crazy = new ttypes.Insanity({ |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 133 | userMap: { 5: 5, 8: 8 }, |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 134 | xtructs: [ |
| 135 | new ttypes.Xtruct({ |
| 136 | string_thing: "Goodbye4", |
| 137 | byte_thing: 4, |
| 138 | i32_thing: 4, |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 139 | i64_thing: 4, |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 140 | }), |
| 141 | new ttypes.Xtruct({ |
| 142 | string_thing: "Hello2", |
| 143 | byte_thing: 2, |
| 144 | i32_thing: 2, |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 145 | i64_thing: 2, |
| 146 | }), |
| 147 | ], |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 148 | }); |
| 149 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 150 | export const crazy2 = new ttypes.Insanity({ |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 151 | userMap: { 5: 5, 8: 8 }, |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 152 | xtructs: [ |
| 153 | { |
| 154 | string_thing: "Goodbye4", |
| 155 | byte_thing: 4, |
| 156 | i32_thing: 4, |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 157 | i64_thing: 4, |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 158 | }, |
| 159 | { |
| 160 | string_thing: "Hello2", |
| 161 | byte_thing: 2, |
| 162 | i32_thing: 2, |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 163 | i64_thing: 2, |
| 164 | }, |
| 165 | ], |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 166 | }); |
| 167 | |
Cameron Martin | 21ed4a2 | 2024-04-22 11:08:19 +0100 | [diff] [blame] | 168 | export const insanity = { |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 169 | 1: { 2: crazy, 3: crazy }, |
| 170 | 2: { 6: { userMap: {}, xtructs: [] } }, |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 171 | }; |