blob: 543e3539ce1fd5aa1595eb227019c7fe573731e2 [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";
24
25const ttypes = await helpers.importTypes(`ThriftTest_types`);
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080026
27//all Languages in UTF-8
28/*jshint -W100 */
Cameron Martin21ed4a22024-04-22 11:08:19 +010029export const stringTest =
bforbisda1169d2018-10-28 11:27:38 -040030 "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 Martin21ed4a22024-04-22 11:08:19 +010054 "Bân-lâm-gú, 粵語";
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080055/*jshint +W100 */
56
Cameron Martin21ed4a22024-04-22 11:08:19 +010057export const specialCharacters =
bforbisda1169d2018-10-28 11:27:38 -040058 '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 Martin21ed4a22024-04-22 11:08:19 +010063 ' char-to-test-json-parsing: ]] "]] \\" }}}{ [[[ ';
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080064
Cameron Martin21ed4a22024-04-22 11:08:19 +010065export const mapTestInput = {
bforbisda1169d2018-10-28 11:27:38 -040066 a: "123",
67 "a b": "with spaces ",
68 same: "same",
Cameron Martincaef0ed2025-01-15 11:58:39 +010069 0: "numeric key",
bforbisda1169d2018-10-28 11:27:38 -040070 longValue: stringTest,
Cameron Martincaef0ed2025-01-15 11:58:39 +010071 stringTest: "long key",
Cameron Martin21ed4a22024-04-22 11:08:19 +010072};
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080073
Cameron Martin21ed4a22024-04-22 11:08:19 +010074export const simple = [
bforbisda1169d2018-10-28 11:27:38 -040075 ["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 Martincaef0ed2025-01-15 11:58:39 +010097 new Int64(new Buffer([0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])),
bforbisda1169d2018-10-28 11:27:38 -040098 ], // -2^53-1
Cameron Martincaef0ed2025-01-15 11:58:39 +010099 ["testTypedef", 69],
bforbisda1169d2018-10-28 11:27:38 -0400100];
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800101
bforbisda1169d2018-10-28 11:27:38 -0400102const mapout = {};
103for (let i = 0; i < 5; ++i) {
104 mapout[i] = i - 10;
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800105}
106
Cameron Martin21ed4a22024-04-22 11:08:19 +0100107export const deep = [
bforbisda1169d2018-10-28 11:27:38 -0400108 [
109 "testList",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100110 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
111 ],
Randy Abernethy983bf7d2015-10-09 12:28:57 -0700112];
113
Cameron Martin21ed4a22024-04-22 11:08:19 +0100114export const deepUnordered = [
bforbisda1169d2018-10-28 11:27:38 -0400115 ["testMap", mapout],
116 ["testSet", [1, 2, 3]],
Cameron Martincaef0ed2025-01-15 11:58:39 +0100117 ["testStringMap", mapTestInput],
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800118];
119
Cameron Martin21ed4a22024-04-22 11:08:19 +0100120export const out = new ttypes.Xtruct({
bforbisda1169d2018-10-28 11:27:38 -0400121 string_thing: "Zero",
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800122 byte_thing: 1,
123 i32_thing: -3,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100124 i64_thing: 1000000,
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800125});
126
Cameron Martin21ed4a22024-04-22 11:08:19 +0100127export const out2 = new ttypes.Xtruct2();
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800128out2.byte_thing = 1;
129out2.struct_thing = out;
130out2.i32_thing = 5;
131
Cameron Martin21ed4a22024-04-22 11:08:19 +0100132export const crazy = new ttypes.Insanity({
Cameron Martincaef0ed2025-01-15 11:58:39 +0100133 userMap: { 5: 5, 8: 8 },
bforbisda1169d2018-10-28 11:27:38 -0400134 xtructs: [
135 new ttypes.Xtruct({
136 string_thing: "Goodbye4",
137 byte_thing: 4,
138 i32_thing: 4,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100139 i64_thing: 4,
bforbisda1169d2018-10-28 11:27:38 -0400140 }),
141 new ttypes.Xtruct({
142 string_thing: "Hello2",
143 byte_thing: 2,
144 i32_thing: 2,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100145 i64_thing: 2,
146 }),
147 ],
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800148});
149
Cameron Martin21ed4a22024-04-22 11:08:19 +0100150export const crazy2 = new ttypes.Insanity({
Cameron Martincaef0ed2025-01-15 11:58:39 +0100151 userMap: { 5: 5, 8: 8 },
bforbisda1169d2018-10-28 11:27:38 -0400152 xtructs: [
153 {
154 string_thing: "Goodbye4",
155 byte_thing: 4,
156 i32_thing: 4,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100157 i64_thing: 4,
bforbisda1169d2018-10-28 11:27:38 -0400158 },
159 {
160 string_thing: "Hello2",
161 byte_thing: 2,
162 i32_thing: 2,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100163 i64_thing: 2,
164 },
165 ],
Henrique Mendonça15d90422015-06-25 22:31:41 +1000166});
167
Cameron Martin21ed4a22024-04-22 11:08:19 +0100168export const insanity = {
Cameron Martincaef0ed2025-01-15 11:58:39 +0100169 1: { 2: crazy, 3: crazy },
170 2: { 6: { userMap: {}, xtructs: [] } },
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800171};