blob: cdc15fb03210ac2c48d60019269a6e38c2f7d50d [file] [log] [blame] [raw]
Partoufb99cc612018-09-26 00:17:49 +02001// Copyright (c) 2018, Compiler Explorer Authors
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// * Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above copyright
10// notice, this list of conditions and the following disclaimer in the
11// documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ,
22// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23// POSSIBILITY OF SUCH DAMAGE.
24"use strict"
25
26const should = require('chai').should();
27const clientstate = require('../lib/clientstate');
28const fs = require('fs');
29const ClientStateNormalizer = require('../lib/clientstate-normalizer').ClientStateNormalizer;
30
31describe("Normalizing clientstate", () => {
32 it("Should translate 2 compilers GL layout to clientstate", () => {
33 const normalizer = new ClientStateNormalizer();
34
35 const data = JSON.parse(fs.readFileSync("test/state/twocompilers.json"));
36
37 normalizer.fromGoldenLayout(data);
38
39 const resultdata = JSON.parse(fs.readFileSync("test/state/twocompilers.json.normalized"));
40
41 normalizer.normalized.should.deep.equal(resultdata);
42 });
Partouf1b6ddc32018-09-30 11:35:41 +020043
44 it("Should recognize everything and kitchensink as well", () => {
45 const normalizer = new ClientStateNormalizer();
46
47 const data = JSON.parse(fs.readFileSync("test/state/andthekitchensink.json"));
48
49 normalizer.fromGoldenLayout(data);
50
51 const resultdata = JSON.parse(fs.readFileSync("test/state/andthekitchensink.json.normalized"));
52
53 normalizer.normalized.should.deep.equal(resultdata);
54 });
Partoufa51ebd42018-10-14 00:39:58 +020055
56 it("Should support conformanceview", () => {
57 const normalizer = new ClientStateNormalizer();
58
59 const data = JSON.parse(fs.readFileSync("test/state/conformanceview.json"));
60
61 normalizer.fromGoldenLayout(data);
62
63 const resultdata = JSON.parse(fs.readFileSync("test/state/conformanceview.json.normalized"));
64
65 normalizer.normalized.should.deep.equal(resultdata);
66 });
Partoufd5659af2019-09-07 17:51:54 +020067
68 it("Should support executors", () => {
69 const normalizer = new ClientStateNormalizer();
70
71 const data = JSON.parse(fs.readFileSync("test/state/executor.json"));
72
73 normalizer.fromGoldenLayout(data);
74
75 const resultdata = JSON.parse(fs.readFileSync("test/state/executor.json.normalized"));
76
77 normalizer.normalized.should.deep.equal(resultdata);
78 });
Partoufb99cc612018-09-26 00:17:49 +020079});
Partouf6841aa32019-09-21 04:46:55 +020080
81describe("ClientState parsing", () => {
82 it("Should work without executors", () => {
83 const state = new clientstate.State({
84 "sessions": [
85 {"id":1,
86 "language":"c++",
87 "source":"int main() {}",
88 "compilers":[{"id":"g91","options":"-O3 -std=c++2a"}]
89 }]
90 });
91
92 state.sessions[0].compilers.length.should.equal(1);
93 state.sessions[0].executors.length.should.equal(0);
94 });
95
96 it("Should work with executor", () => {
97 const state = new clientstate.State({
98 "sessions": [
99 {"id":1,
100 "language":"c++",
101 "source":"int main() {}",
102 "compilers": [],
103 "executors":[{
104 "compiler":{"id":"g91","options":"-O3 -std=c++2a"}
105 }]
106 }]
107 });
108
109 state.sessions[0].compilers.length.should.equal(0);
110 state.sessions[0].executors.length.should.equal(1);
111 });
112});