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