blob: c074923ba432ed855ffe7208656e889db76a8682 [file] [log] [blame]
James E. King, III375bfee2017-10-26 00:09:34 -04001/*
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
bforbisda1169d2018-10-28 11:27:38 -040020"use strict";
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080021
Cameron Martin21ed4a22024-04-22 11:08:19 +010022import helpers from "./helpers.js";
23import Int64 from "node-int64";
CJCombrinkdfeab8d2026-03-06 07:03:56 +010024import { v4 as uuidv4, v7 as uuidv7 } from "uuid";
Cameron Martin21ed4a22024-04-22 11:08:19 +010025
26const ttypes = await helpers.importTypes(`ThriftTest_types`);
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080027
28//all Languages in UTF-8
29/*jshint -W100 */
Cameron Martin21ed4a22024-04-22 11:08:19 +010030export const stringTest =
bforbisda1169d2018-10-28 11:27:38 -040031 "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 Martin21ed4a22024-04-22 11:08:19 +010055 "Bân-lâm-gú, 粵語";
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080056/*jshint +W100 */
57
Cameron Martin21ed4a22024-04-22 11:08:19 +010058export const specialCharacters =
bforbisda1169d2018-10-28 11:27:38 -040059 '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 Martin21ed4a22024-04-22 11:08:19 +010064 ' char-to-test-json-parsing: ]] "]] \\" }}}{ [[[ ';
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080065
Cameron Martin21ed4a22024-04-22 11:08:19 +010066export const mapTestInput = {
bforbisda1169d2018-10-28 11:27:38 -040067 a: "123",
68 "a b": "with spaces ",
69 same: "same",
Cameron Martincaef0ed2025-01-15 11:58:39 +010070 0: "numeric key",
bforbisda1169d2018-10-28 11:27:38 -040071 longValue: stringTest,
Cameron Martincaef0ed2025-01-15 11:58:39 +010072 stringTest: "long key",
Cameron Martin21ed4a22024-04-22 11:08:19 +010073};
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080074
Cameron Martin21ed4a22024-04-22 11:08:19 +010075export const simple = [
bforbisda1169d2018-10-28 11:27:38 -040076 ["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 Martincaef0ed2025-01-15 11:58:39 +010098 new Int64(new Buffer([0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])),
bforbisda1169d2018-10-28 11:27:38 -040099 ], // -2^53-1
Cameron Martincaef0ed2025-01-15 11:58:39 +0100100 ["testTypedef", 69],
CJCombrinkdfeab8d2026-03-06 07:03:56 +0100101 ["testUuid", "00112233-4455-6677-8899-aabbccddeeff"],
102 ["testUuid", uuidv4()],
103 ["testUuid", uuidv7()],
bforbisda1169d2018-10-28 11:27:38 -0400104];
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800105
bforbisda1169d2018-10-28 11:27:38 -0400106const mapout = {};
107for (let i = 0; i < 5; ++i) {
108 mapout[i] = i - 10;
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800109}
110
Cameron Martin21ed4a22024-04-22 11:08:19 +0100111export const deep = [
bforbisda1169d2018-10-28 11:27:38 -0400112 [
113 "testList",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100114 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
115 ],
Randy Abernethy983bf7d2015-10-09 12:28:57 -0700116];
117
Cameron Martin21ed4a22024-04-22 11:08:19 +0100118export const deepUnordered = [
bforbisda1169d2018-10-28 11:27:38 -0400119 ["testMap", mapout],
120 ["testSet", [1, 2, 3]],
Cameron Martincaef0ed2025-01-15 11:58:39 +0100121 ["testStringMap", mapTestInput],
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800122];
123
Cameron Martin21ed4a22024-04-22 11:08:19 +0100124export const out = new ttypes.Xtruct({
bforbisda1169d2018-10-28 11:27:38 -0400125 string_thing: "Zero",
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800126 byte_thing: 1,
127 i32_thing: -3,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100128 i64_thing: 1000000,
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800129});
130
Cameron Martin21ed4a22024-04-22 11:08:19 +0100131export const out2 = new ttypes.Xtruct2();
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800132out2.byte_thing = 1;
133out2.struct_thing = out;
134out2.i32_thing = 5;
135
Cameron Martin21ed4a22024-04-22 11:08:19 +0100136export const crazy = new ttypes.Insanity({
Cameron Martincaef0ed2025-01-15 11:58:39 +0100137 userMap: { 5: 5, 8: 8 },
bforbisda1169d2018-10-28 11:27:38 -0400138 xtructs: [
139 new ttypes.Xtruct({
140 string_thing: "Goodbye4",
141 byte_thing: 4,
142 i32_thing: 4,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100143 i64_thing: 4,
bforbisda1169d2018-10-28 11:27:38 -0400144 }),
145 new ttypes.Xtruct({
146 string_thing: "Hello2",
147 byte_thing: 2,
148 i32_thing: 2,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100149 i64_thing: 2,
150 }),
151 ],
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800152});
153
Cameron Martin21ed4a22024-04-22 11:08:19 +0100154export const crazy2 = new ttypes.Insanity({
Cameron Martincaef0ed2025-01-15 11:58:39 +0100155 userMap: { 5: 5, 8: 8 },
bforbisda1169d2018-10-28 11:27:38 -0400156 xtructs: [
157 {
158 string_thing: "Goodbye4",
159 byte_thing: 4,
160 i32_thing: 4,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100161 i64_thing: 4,
bforbisda1169d2018-10-28 11:27:38 -0400162 },
163 {
164 string_thing: "Hello2",
165 byte_thing: 2,
166 i32_thing: 2,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100167 i64_thing: 2,
168 },
169 ],
Henrique Mendonça15d90422015-06-25 22:31:41 +1000170});
171
Cameron Martin21ed4a22024-04-22 11:08:19 +0100172export const insanity = {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100173 1: { 2: crazy, 3: crazy },
174 2: { 6: { userMap: {}, xtructs: [] } },
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800175};