QL code and tests for C#/C++/JavaScript.

This commit is contained in:
Pavel Avgustinov
2018-08-02 17:53:23 +01:00
commit b55526aa58
10684 changed files with 581163 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
function f() {
if (cond1())
if (cond2())
return 23;
else
return 42;
return 56;
}

View File

@@ -0,0 +1,8 @@
function f() {
if (cond1())
if (cond2())
return 23;
else
return 42;
return 56;
}

View File

@@ -0,0 +1,10 @@
function f() {
if (cond1()) {
if (cond2()) {
return 23;
} else {
return 42;
}
}
return 56;
}

View File

@@ -0,0 +1,24 @@
function nextToken(reader){
var c = reader.read(), token = null;
while (c) {
switch(c) {
case "/":
if(reader.peek() == "*")
token = commentToken(reader, c, startLine, startCol);
else
token = charToken(reader, c, startLine, startCol);
break;
case '"':
case "'":
token = stringToken(c, startLine, startCol);
break;
default:
token = charToken(reader, c, startLine, startCol);
}
break;
}
return token;
}

View File

@@ -0,0 +1,22 @@
function nextToken(reader){
var c = reader.read(), token = null;
if (c) {
switch(c) {
case "/":
if(reader.peek() == "*")
token = commentToken(reader, c, startLine, startCol);
else
token = charToken(reader, c, startLine, startCol);
break;
case '"':
case "'":
token = stringToken(c, startLine, startCol);
break;
default:
token = charToken(reader, c, startLine, startCol);
}
}
return token;
}

View File

@@ -0,0 +1,4 @@
function call(o, m) {
if (o && typeof o[m] === 'function')
return o[m]();
}

View File

@@ -0,0 +1,5 @@
function call(o, m) {
if (o && typeof o[m] === 'function')
return o[m]();
throw new Error("no such method");
}

View File

@@ -0,0 +1,7 @@
// zero out everything below index `lower`
for (i=lower-1; i>=0; --i)
a[i] = 0;
// zero out everything above index `upper`
for (i=upper+1; i<a.length; --i)
a[i] = 0;

View File

@@ -0,0 +1,7 @@
// zero out everything below index `lower`
for (i=lower-1; i>=0; --i)
a[i] = 0;
// zero out everything above index `upper`
for (i=upper+1; i<a.length; ++i)
a[i] = 0;

View File

@@ -0,0 +1,5 @@
function solve_quad(a, b, c) {
if (a === 0 || b*b < 4*a*c)
return;
return (-b + Math.sqrt(b*b - 4*a*c))/(2*a);
}

View File

@@ -0,0 +1,5 @@
function solve_quad(a, b, c) {
if (a === 0 || b*b < 4*a*c)
return void 0;
return (-b + Math.sqrt(b*b - 4*a*c))/(2*a);
}

View File

@@ -0,0 +1,10 @@
function f(x) {
switch (x) {
case 1:
case 2:
case3:
return true;
default:
return false;
}
}

View File

@@ -0,0 +1,3 @@
if (afraid())
scream();
runAway();

View File

@@ -0,0 +1,4 @@
if (afraid()) {
scream();
runAway();
}

View File

@@ -0,0 +1,3 @@
if (afraid())
scream();
runAway();

View File

@@ -0,0 +1,5 @@
for (var i=0; i<10; ++i) {
// NOT OK
for (var j=i; i>5; --i)
f(i, j);
}

View File

@@ -0,0 +1,5 @@
for (var i=0; i<10; ++i) {
// NOT OK
for (var j=i; j>5; --j)
f(i, j);
}

View File

@@ -0,0 +1,10 @@
function Person(first, last, age) {
this.first = first;
this.last = last;
this.age = age;
}
Person.prototype.getName = function() {
var name = first + " " + last;
return name = name.trim();
};

View File

@@ -0,0 +1,10 @@
function Person(first, last, age) {
this.first = first;
this.last = last;
this.age = age;
}
Person.prototype.getName = function() {
var name = first + " " + last;
return name.trim();
};

View File

@@ -0,0 +1,3 @@
<form name="f" action="javascript:return validateForm(this);" method="post">
<!-- form contents -->
</form>

View File

@@ -0,0 +1,3 @@
<form name="f" onsubmit="return validateForm(this);" method="post">
<!-- form contents -->
</form>

View File

@@ -0,0 +1,7 @@
function countOccurrences(xs, p) {
var count = 0;
for (let x of xs)
if (p())
++count;
return count;
}

View File

@@ -0,0 +1,5 @@
function f() {
if (someCond());
return 23;
return 42;
}

View File

@@ -0,0 +1,5 @@
function f() {
if (someCond())
return 23;
return 42;
}

View File

@@ -0,0 +1,8 @@
function getLastLine(input) {
var lines = [], nextLine;
while ((nextLine = readNextLine(input)))
lines.push(nextLine);
if (!lines)
throw new Error("No lines!");
return lines[lines.length-1];
}

View File

@@ -0,0 +1,8 @@
function getLastLine(input) {
var lines = [], nextLine;
while ((nextLine = readNextLine(input)))
lines.push(nextLine);
if (!lines.length)
throw new Error("No lines!");
return lines[lines.length-1];
}