Added a new scripting language (PlanA).

Closes #15136
This commit is contained in:
Jack Conradson 2015-12-09 16:32:37 -08:00
parent 414fccb7d1
commit da5b07ae13
70 changed files with 19804 additions and 0 deletions

View File

@ -83,6 +83,7 @@ public class PluginManager {
"discovery-gce",
"discovery-multicast",
"lang-javascript",
"lang-plan-a",
"lang-python",
"mapper-attachments",
"mapper-murmur3",

View File

@ -44,6 +44,7 @@ OFFICIAL PLUGINS
- discovery-gce
- discovery-multicast
- lang-javascript
- lang-plan-a
- lang-python
- mapper-attachments
- mapper-murmur3

View File

@ -70,6 +70,7 @@ DEFAULT_PLUGINS = ["analysis-icu",
"lang-expression",
"lang-groovy",
"lang-javascript",
"lang-plan-a",
"lang-python",
"mapper-murmur3",
"mapper-size",

145
plugins/lang-plan-a/ant.xml Normal file
View File

@ -0,0 +1,145 @@
<?xml version="1.0"?>
<project name="ant-stuff">
<!--
grammar regeneration logic
we do this with ant for several reasons:
* remove generated tabs for forbidden-apis
* remove generated timestamps/filenames for reproducible build
* fix CRLF line endings for windows consistency
* ability to make classes package-private
* keeping in source code control is easier on IDEs
* regeneration should be rare, no reason to be religious about generated files
* all logic already written and battle tested in lucene build
-->
<target name="regenerate" description="Regenerate antlr lexer and parser" depends="run-antlr"/>
<target name="run-antlr">
<regen-delete grammar="PlanA"/>
<regen-lexer grammar="PlanA"/>
<regen-parser grammar="PlanA"/>
<regen-fix grammar="PlanA"/>
</target>
<macrodef name="replace-value">
<attribute name="value" />
<attribute name="property" />
<attribute name="from" />
<attribute name="to" />
<sequential>
<loadresource property="@{property}">
<string value="@{value}"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replacestring from="@{from}" to="@{to}"/>
</tokenfilter>
</filterchain>
</loadresource>
</sequential>
</macrodef>
<macrodef name="regen-delete">
<attribute name="grammar" />
<sequential>
<local name="output.path"/>
<patternset id="grammar.@{grammar}.patternset">
<include name="@{grammar}Lexer.java" />
<include name="@{grammar}Parser.java" />
<include name="@{grammar}ParserVisitor.java" />
<include name="@{grammar}ParserBaseVisitor.java" />
</patternset>
<property name="output.path" location="src/main/java/org/elasticsearch/plan/a"/>
<!-- delete parser and lexer so files will be generated -->
<delete dir="${output.path}">
<patternset refid="grammar.@{grammar}.patternset"/>
</delete>
</sequential>
</macrodef>
<macrodef name="regen-lexer">
<attribute name="grammar" />
<sequential>
<local name="grammar.path"/>
<local name="output.path"/>
<property name="grammar.path" location="src/main/antlr"/>
<property name="output.path" location="src/main/java/org/elasticsearch/plan/a"/>
<!-- invoke ANTLR4 -->
<java classname="org.antlr.v4.Tool" fork="true" failonerror="true" classpathref="regenerate.classpath" taskname="antlr">
<sysproperty key="file.encoding" value="UTF-8"/>
<sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/>
<sysproperty key="user.variant" value=""/>
<arg value="-package"/>
<arg value="org.elasticsearch.plan.a"/>
<arg value="-o"/>
<arg path="${output.path}"/>
<arg path="${grammar.path}/@{grammar}Lexer.g4"/>
</java>
</sequential>
</macrodef>
<macrodef name="regen-parser">
<attribute name="grammar" />
<sequential>
<local name="grammar.path"/>
<local name="output.path"/>
<property name="grammar.path" location="src/main/antlr"/>
<property name="output.path" location="src/main/java/org/elasticsearch/plan/a"/>
<!-- invoke ANTLR4 -->
<java classname="org.antlr.v4.Tool" fork="true" failonerror="true" classpathref="regenerate.classpath" taskname="antlr">
<sysproperty key="file.encoding" value="UTF-8"/>
<sysproperty key="user.language" value="en"/>
<sysproperty key="user.country" value="US"/>
<sysproperty key="user.variant" value=""/>
<arg value="-package"/>
<arg value="org.elasticsearch.plan.a"/>
<arg value="-no-listener"/>
<arg value="-visitor"/>
<!-- <arg value="-Xlog"/> -->
<arg value="-o"/>
<arg path="${output.path}"/>
<arg path="${grammar.path}/@{grammar}Parser.g4"/>
</java>
</sequential>
</macrodef>
<macrodef name="regen-fix">
<attribute name="grammar" />
<sequential>
<local name="grammar.path"/>
<local name="output.path"/>
<property name="grammar.path" location="src/main/antlr"/>
<property name="output.path" location="src/main/java/org/elasticsearch/plan/a"/>
<patternset id="grammar.@{grammar}.patternset">
<include name="@{grammar}Lexer.java" />
<include name="@{grammar}Parser.java" />
<include name="@{grammar}ParserVisitor.java" />
<include name="@{grammar}ParserBaseVisitor.java" />
</patternset>
<!-- fileset with files to edit -->
<fileset id="grammar.fileset" dir="${output.path}">
<patternset refid="grammar.@{grammar}.patternset"/>
</fileset>
<!-- remove files that are not needed to compile or at runtime -->
<delete dir="${grammar.path}" includes="@{grammar}*.tokens"/>
<delete dir="${output.path}" includes="@{grammar}*.tokens"/>
<!-- make the generated classes package private -->
<replaceregexp match="public ((interface|class) \Q@{grammar}\E\w+)" replace="\1" encoding="UTF-8">
<fileset refid="grammar.fileset"/>
</replaceregexp>
<!-- nuke timestamps/filenames in generated files -->
<replaceregexp match="\Q// Generated from \E.*" replace="\/\/ ANTLR GENERATED CODE: DO NOT EDIT" encoding="UTF-8">
<fileset refid="grammar.fileset"/>
</replaceregexp>
<!-- remove tabs in antlr generated files -->
<replaceregexp match="\t" flags="g" replace=" " encoding="UTF-8">
<fileset refid="grammar.fileset"/>
</replaceregexp>
<!-- fix line endings -->
<fixcrlf srcdir="${output.path}">
<patternset refid="grammar.@{grammar}.patternset"/>
</fixcrlf>
</sequential>
</macrodef>
</project>

View File

@ -0,0 +1,48 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.tools.ant.types.Path
esplugin {
description 'An easy, safe and fast scripting language for Elasticsearch'
classname 'org.elasticsearch.plan.a.PlanAPlugin'
}
dependencies {
compile 'org.antlr:antlr4-runtime:4.5.1-1'
compile 'org.ow2.asm:asm:5.0.4'
compile 'org.ow2.asm:asm-commons:5.0.4'
}
compileJava.options.compilerArgs << '-Xlint:-cast,-fallthrough,-rawtypes'
compileTestJava.options.compilerArgs << '-Xlint:-unchecked'
// regeneration logic, comes in via ant right now
// don't port it to gradle, it works fine.
configurations {
regenerate
}
dependencies {
regenerate 'org.antlr:antlr4:4.5.1-1'
}
ant.references['regenerate.classpath'] = new Path(ant.project, configurations.regenerate.asPath)
ant.importBuild 'ant.xml'

View File

@ -0,0 +1 @@
66144204f9d6d7d3f3f775622c2dd7e9bd511d97

View File

@ -0,0 +1,26 @@
[The "BSD license"]
Copyright (c) 2015 Terence Parr, Sam Harwell
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1 @@
0da08b8cce7bbf903602a25a3a163ae252435795

View File

@ -0,0 +1,26 @@
Copyright (c) 2012 France Télécom
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
5a556786086c23cd689a0328f8519db93821c04c

View File

@ -0,0 +1,26 @@
Copyright (c) 2012 France Télécom
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,120 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
lexer grammar PlanALexer;
@header {
import java.util.Set;
}
@members {
private Set<String> types = null;
void setTypes(Set<String> types) {
this.types = types;
}
}
WS: [ \t\n\r]+ -> skip;
COMMENT: ( '//' .*? [\n\r] | '/*' .*? '*/' ) -> skip;
LBRACK: '{';
RBRACK: '}';
LBRACE: '[';
RBRACE: ']';
LP: '(';
RP: ')';
DOT: '.' -> mode(EXT);
COMMA: ',';
SEMICOLON: ';';
IF: 'if';
ELSE: 'else';
WHILE: 'while';
DO: 'do';
FOR: 'for';
CONTINUE: 'continue';
BREAK: 'break';
RETURN: 'return';
NEW: 'new';
TRY: 'try';
CATCH: 'catch';
THROW: 'throw';
BOOLNOT: '!';
BWNOT: '~';
MUL: '*';
DIV: '/';
REM: '%';
ADD: '+';
SUB: '-';
LSH: '<<';
RSH: '>>';
USH: '>>>';
LT: '<';
LTE: '<=';
GT: '>';
GTE: '>=';
EQ: '==';
EQR: '===';
NE: '!=';
NER: '!==';
BWAND: '&';
BWXOR: '^';
BWOR: '|';
BOOLAND: '&&';
BOOLOR: '||';
COND: '?';
COLON: ':';
INCR: '++';
DECR: '--';
ASSIGN: '=';
AADD: '+=';
ASUB: '-=';
AMUL: '*=';
ADIV: '/=';
AREM: '%=';
AAND: '&=';
AXOR: '^=';
AOR: '|=';
ALSH: '<<=';
ARSH: '>>=';
AUSH: '>>>=';
ACAT: '..=';
OCTAL: '0' [0-7]+ [lL]?;
HEX: '0' [xX] [0-9a-fA-F]+ [lL]?;
INTEGER: ( '0' | [1-9] [0-9]* ) [lLfFdD]?;
DECIMAL: ( '0' | [1-9] [0-9]* ) DOT [0-9]* ( [eE] [+\-]? [0-9]+ )? [fF]?;
STRING: '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' {setText(getText().substring(1, getText().length() - 1));};
CHAR: '\'' . '\'' {setText(getText().substring(1, getText().length() - 1));};
TRUE: 'true';
FALSE: 'false';
NULL: 'null';
TYPE: ID GENERIC? {types.contains(getText().replace(" ", ""))}? {setText(getText().replace(" ", ""));};
fragment GENERIC: ' '* '<' ' '* ( ID GENERIC? ) ' '* ( COMMA ' '* ( ID GENERIC? ) ' '* )* '>';
ID: [_a-zA-Z] [_a-zA-Z0-9]*;
mode EXT;
EXTINTEGER: ( '0' | [1-9] [0-9]* ) -> mode(DEFAULT_MODE);
EXTID: [_a-zA-Z] [_a-zA-Z0-9]* -> mode(DEFAULT_MODE);

View File

@ -0,0 +1,127 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
parser grammar PlanAParser;
options { tokenVocab=PlanALexer; }
source
: statement+ EOF
;
statement
: IF LP expression RP block ( ELSE block )? # if
| WHILE LP expression RP ( block | empty ) # while
| DO block WHILE LP expression RP SEMICOLON? # do
| FOR LP initializer? SEMICOLON expression? SEMICOLON afterthought? RP ( block | empty ) # for
| declaration SEMICOLON? # decl
| CONTINUE SEMICOLON? # continue
| BREAK SEMICOLON? # break
| RETURN expression SEMICOLON? # return
| TRY block ( CATCH LP ( TYPE ID ) RP block )+ # try
| THROW expression SEMICOLON? # throw
| expression SEMICOLON? # expr
;
block
: LBRACK statement* RBRACK # multiple
| statement # single
;
empty
: SEMICOLON
;
initializer
: declaration
| expression
;
afterthought
: expression
;
declaration
: decltype declvar ( COMMA declvar )*
;
decltype
: TYPE (LBRACE RBRACE)*
;
declvar
: ID ( ASSIGN expression )?
;
expression
: LP expression RP # precedence
| ( OCTAL | HEX | INTEGER | DECIMAL ) # numeric
| CHAR # char
| TRUE # true
| FALSE # false
| NULL # null
| <assoc=right> extstart increment # postinc
| <assoc=right> increment extstart # preinc
| extstart # external
| <assoc=right> ( BOOLNOT | BWNOT | ADD | SUB ) expression # unary
| <assoc=right> LP decltype RP expression # cast
| expression ( MUL | DIV | REM ) expression # binary
| expression ( ADD | SUB ) expression # binary
| expression ( LSH | RSH | USH ) expression # binary
| expression ( LT | LTE | GT | GTE ) expression # comp
| expression ( EQ | EQR | NE | NER ) expression # comp
| expression BWAND expression # binary
| expression BWXOR expression # binary
| expression BWOR expression # binary
| expression BOOLAND expression # bool
| expression BOOLOR expression # bool
| <assoc=right> expression COND expression COLON expression # conditional
| <assoc=right> extstart ( ASSIGN | AADD | ASUB | AMUL | ADIV
| AREM | AAND | AXOR | AOR
| ALSH | ARSH | AUSH ) expression # assignment
;
extstart
: extprec
| extcast
| exttype
| extvar
| extnew
| extstring
;
extprec: LP ( extprec | extcast | exttype | extvar | extnew | extstring ) RP ( extdot | extbrace )?;
extcast: LP decltype RP ( extprec | extcast | exttype | extvar | extnew | extstring );
extbrace: LBRACE expression RBRACE ( extdot | extbrace )?;
extdot: DOT ( extcall | extfield );
exttype: TYPE extdot;
extcall: EXTID arguments ( extdot | extbrace )?;
extvar: ID ( extdot | extbrace )?;
extfield: ( EXTID | EXTINTEGER ) ( extdot | extbrace )?;
extnew: NEW TYPE ( ( arguments ( extdot | extbrace)? ) | ( ( LBRACE expression RBRACE )+ extdot? ) );
extstring: STRING (extdot | extbrace )?;
arguments
: ( LP ( expression ( COMMA expression )* )? RP )
;
increment
: INCR
| DECR
;

View File

@ -0,0 +1,276 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import java.util.HashMap;
import java.util.Map;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;
import static org.elasticsearch.plan.a.Definition.*;
import static org.elasticsearch.plan.a.PlanAParser.*;
class Adapter {
static class StatementMetadata {
final ParserRuleContext source;
boolean last;
boolean allExit;
boolean allReturn;
boolean anyReturn;
boolean allBreak;
boolean anyBreak;
boolean allContinue;
boolean anyContinue;
private StatementMetadata(final ParserRuleContext source) {
this.source = source;
last = false;
allExit = false;
allReturn = false;
anyReturn = false;
allBreak = false;
anyBreak = false;
allContinue = false;
anyContinue = false;
}
}
static class ExpressionMetadata {
final ParserRuleContext source;
boolean read;
boolean statement;
Object preConst;
Object postConst;
boolean isNull;
Type to;
Type from;
boolean explicit;
boolean typesafe;
Cast cast;
private ExpressionMetadata(final ParserRuleContext source) {
this.source = source;
read = true;
statement = false;
preConst = null;
postConst = null;
isNull = false;
to = null;
from = null;
explicit = false;
typesafe = true;
cast = null;
}
}
static class ExternalMetadata {
final ParserRuleContext source;
boolean read;
ParserRuleContext storeExpr;
int token;
boolean pre;
boolean post;
int scope;
Type current;
boolean statik;
boolean statement;
Object constant;
private ExternalMetadata(final ParserRuleContext source) {
this.source = source;
read = false;
storeExpr = null;
token = 0;
pre = false;
post = false;
scope = 0;
current = null;
statik = false;
statement = false;
constant = null;
}
}
static class ExtNodeMetadata {
final ParserRuleContext parent;
final ParserRuleContext source;
Object target;
boolean last;
Type type;
Type promote;
Cast castFrom;
Cast castTo;
private ExtNodeMetadata(final ParserRuleContext parent, final ParserRuleContext source) {
this.parent = parent;
this.source = source;
target = null;
last = false;
type = null;
promote = null;
castFrom = null;
castTo = null;
}
}
static String error(final ParserRuleContext ctx) {
return "Error [" + ctx.getStart().getLine() + ":" + ctx.getStart().getCharPositionInLine() + "]: ";
}
final Definition definition;
final String source;
final ParserRuleContext root;
final CompilerSettings settings;
private final Map<ParserRuleContext, StatementMetadata> statementMetadata;
private final Map<ParserRuleContext, ExpressionMetadata> expressionMetadata;
private final Map<ParserRuleContext, ExternalMetadata> externalMetadata;
private final Map<ParserRuleContext, ExtNodeMetadata> extNodeMetadata;
Adapter(final Definition definition, final String source, final ParserRuleContext root, final CompilerSettings settings) {
this.definition = definition;
this.source = source;
this.root = root;
this.settings = settings;
statementMetadata = new HashMap<>();
expressionMetadata = new HashMap<>();
externalMetadata = new HashMap<>();
extNodeMetadata = new HashMap<>();
}
StatementMetadata createStatementMetadata(final ParserRuleContext source) {
final StatementMetadata sourcesmd = new StatementMetadata(source);
statementMetadata.put(source, sourcesmd);
return sourcesmd;
}
StatementMetadata getStatementMetadata(final ParserRuleContext source) {
final StatementMetadata sourcesmd = statementMetadata.get(source);
if (sourcesmd == null) {
throw new IllegalStateException(error(source) + "Statement metadata does not exist at" +
" the parse node with text [" + source.getText() + "].");
}
return sourcesmd;
}
ExpressionContext updateExpressionTree(ExpressionContext source) {
if (source instanceof PrecedenceContext) {
final ParserRuleContext parent = source.getParent();
int index = 0;
for (final ParseTree child : parent.children) {
if (child == source) {
break;
}
++index;
}
while (source instanceof PrecedenceContext) {
source = ((PrecedenceContext)source).expression();
}
parent.children.set(index, source);
}
return source;
}
ExpressionMetadata createExpressionMetadata(ParserRuleContext source) {
final ExpressionMetadata sourceemd = new ExpressionMetadata(source);
expressionMetadata.put(source, sourceemd);
return sourceemd;
}
ExpressionMetadata getExpressionMetadata(final ParserRuleContext source) {
final ExpressionMetadata sourceemd = expressionMetadata.get(source);
if (sourceemd == null) {
throw new IllegalStateException(error(source) + "Expression metadata does not exist at" +
" the parse node with text [" + source.getText() + "].");
}
return sourceemd;
}
ExternalMetadata createExternalMetadata(final ParserRuleContext source) {
final ExternalMetadata sourceemd = new ExternalMetadata(source);
externalMetadata.put(source, sourceemd);
return sourceemd;
}
ExternalMetadata getExternalMetadata(final ParserRuleContext source) {
final ExternalMetadata sourceemd = externalMetadata.get(source);
if (sourceemd == null) {
throw new IllegalStateException(error(source) + "External metadata does not exist at" +
" the parse node with text [" + source.getText() + "].");
}
return sourceemd;
}
ExtNodeMetadata createExtNodeMetadata(final ParserRuleContext parent, final ParserRuleContext source) {
final ExtNodeMetadata sourceemd = new ExtNodeMetadata(parent, source);
extNodeMetadata.put(source, sourceemd);
return sourceemd;
}
ExtNodeMetadata getExtNodeMetadata(final ParserRuleContext source) {
final ExtNodeMetadata sourceemd = extNodeMetadata.get(source);
if (sourceemd == null) {
throw new IllegalStateException(error(source) + "External metadata does not exist at" +
" the parse node with text [" + source.getText() + "].");
}
return sourceemd;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,154 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.CodeSource;
import java.security.SecureClassLoader;
import java.security.cert.Certificate;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
import org.elasticsearch.bootstrap.BootstrapInfo;
final class Compiler {
private static Definition DEFAULT_DEFINITION = new Definition(new Definition());
/** we define the class with lowest privileges */
private static final CodeSource CODESOURCE;
static {
try {
CODESOURCE = new CodeSource(new URL("file:" + BootstrapInfo.UNTRUSTED_CODEBASE), (Certificate[]) null);
} catch (MalformedURLException impossible) {
throw new RuntimeException(impossible);
}
}
static class Loader extends SecureClassLoader {
Loader(ClassLoader parent) {
super(parent);
}
Class<? extends Executable> define(String name, byte[] bytes) {
return defineClass(name, bytes, 0, bytes.length, CODESOURCE).asSubclass(Executable.class);
}
}
static Executable compile(Loader loader, final String name, final String source, final Definition custom, CompilerSettings settings) {
long start = System.currentTimeMillis();
final Definition definition = custom == null ? DEFAULT_DEFINITION : new Definition(custom);
//long end = System.currentTimeMillis() - start;
//System.out.println("types: " + end);
//start = System.currentTimeMillis();
//final ParserRuleContext root = createParseTree(source, types);
final ANTLRInputStream stream = new ANTLRInputStream(source);
final ErrorHandlingLexer lexer = new ErrorHandlingLexer(stream);
final PlanAParser parser = new PlanAParser(new CommonTokenStream(lexer));
final ParserErrorStrategy strategy = new ParserErrorStrategy();
lexer.removeErrorListeners();
lexer.setTypes(definition.structs.keySet());
//List<? extends Token> tokens = lexer.getAllTokens();
//for (final Token token : tokens) {
// System.out.println(token.getType() + " " + token.getText());
//}
parser.removeErrorListeners();
parser.setErrorHandler(strategy);
ParserRuleContext root = parser.source();
//end = System.currentTimeMillis() - start;
//System.out.println("tree: " + end);
final Adapter adapter = new Adapter(definition, source, root, settings);
start = System.currentTimeMillis();
Analyzer.analyze(adapter);
//System.out.println(root.toStringTree(parser));
//end = System.currentTimeMillis() - start;
//System.out.println("analyze: " + end);
//start = System.currentTimeMillis();
final byte[] bytes = Writer.write(adapter);
//end = System.currentTimeMillis() - start;
//System.out.println("write: " + end);
//start = System.currentTimeMillis();
final Executable executable = createExecutable(loader, definition, name, source, bytes);
//end = System.currentTimeMillis() - start;
//System.out.println("create: " + end);
return executable;
}
private static ParserRuleContext createParseTree(String source, Definition definition) {
final ANTLRInputStream stream = new ANTLRInputStream(source);
final ErrorHandlingLexer lexer = new ErrorHandlingLexer(stream);
final PlanAParser parser = new PlanAParser(new CommonTokenStream(lexer));
final ParserErrorStrategy strategy = new ParserErrorStrategy();
lexer.removeErrorListeners();
lexer.setTypes(definition.structs.keySet());
parser.removeErrorListeners();
parser.setErrorHandler(strategy);
ParserRuleContext root = parser.source();
// System.out.println(root.toStringTree(parser));
return root;
}
private static Executable createExecutable(Loader loader, Definition definition, String name, String source, byte[] bytes) {
try {
// for debugging:
//try {
// FileOutputStream f = new FileOutputStream(new File("/Users/jdconrad/lang/generated/out.class"), false);
// f.write(bytes);
// f.close();
//} catch (Exception e) {
// throw new RuntimeException(e);
//}
final Class<? extends Executable> clazz = loader.define(Writer.CLASS_NAME, bytes);
final java.lang.reflect.Constructor<? extends Executable> constructor =
clazz.getConstructor(Definition.class, String.class, String.class);
return constructor.newInstance(definition, name, source);
} catch (Exception exception) {
throw new IllegalStateException(
"An internal error occurred attempting to define the script [" + name + "].", exception);
}
}
private Compiler() {}
}

View File

@ -0,0 +1,49 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/**
* Settings to use when compiling a script
*/
final class CompilerSettings {
private boolean numericOverflow = true;
/**
* Returns {@code true} if numeric operations should overflow, {@code false}
* if they should signal an exception.
* <p>
* If this value is {@code true} (default), then things behave like java:
* overflow for integer types can result in unexpected values / unexpected
* signs, and overflow for floating point types can result in infinite or
* {@code NaN} values.
*/
public boolean getNumericOverflow() {
return numericOverflow;
}
/**
* Set {@code true} for numerics to overflow, false to deliver exceptions.
* @see #getNumericOverflow
*/
public void setNumericOverflow(boolean allow) {
this.numericOverflow = allow;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
package org.elasticsearch.plan.a;
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.text.ParseException;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.LexerNoViableAltException;
import org.antlr.v4.runtime.misc.Interval;
class ErrorHandlingLexer extends PlanALexer {
public ErrorHandlingLexer(CharStream charStream) {
super(charStream);
}
@Override
public void recover(LexerNoViableAltException lnvae) {
CharStream charStream = lnvae.getInputStream();
int startIndex = lnvae.getStartIndex();
String text = charStream.getText(Interval.of(startIndex, charStream.index()));
ParseException parseException = new ParseException("Error [" + _tokenStartLine + ":" +
_tokenStartCharPositionInLine + "]: unexpected character [" +
getErrorDisplay(text) + "].", _tokenStartCharIndex);
parseException.initCause(lnvae);
throw new RuntimeException(parseException);
}
}

View File

@ -0,0 +1,50 @@
package org.elasticsearch.plan.a;
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.Map;
public abstract class Executable {
protected final Definition definition;
private final String name;
private final String source;
public Executable(final Definition definition, final String name, final String source) {
this.definition = definition;
this.name = name;
this.source = source;
}
public String getName() {
return name;
}
public String getSource() {
return source;
}
public Definition getDefinition() {
return definition;
}
public abstract Object execute(Map<String, Object> input);
}

View File

@ -0,0 +1,74 @@
package org.elasticsearch.plan.a;
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.text.ParseException;
import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.InputMismatchException;
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Token;
class ParserErrorStrategy extends DefaultErrorStrategy {
@Override
public void recover(Parser recognizer, RecognitionException re) {
Token token = re.getOffendingToken();
String message;
if (token == null) {
message = "Error: no parse token found.";
} else if (re instanceof InputMismatchException) {
message = "Error[" + token.getLine() + ":" + token.getCharPositionInLine() + "]:" +
" unexpected token [" + getTokenErrorDisplay(token) + "]" +
" was expecting one of [" + re.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
} else if (re instanceof NoViableAltException) {
if (token.getType() == PlanAParser.EOF) {
message = "Error: unexpected end of script.";
} else {
message = "Error[" + token.getLine() + ":" + token.getCharPositionInLine() + "]:" +
"invalid sequence of tokens near [" + getTokenErrorDisplay(token) + "].";
}
} else {
message = "Error[" + token.getLine() + ":" + token.getCharPositionInLine() + "]:" +
" unexpected token near [" + getTokenErrorDisplay(token) + "].";
}
ParseException parseException = new ParseException(message, token == null ? -1 : token.getStartIndex());
parseException.initCause(re);
throw new RuntimeException(parseException);
}
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
Token token = recognizer.getCurrentToken();
String message = "Error[" + token.getLine() + ":" + token.getCharPositionInLine() + "]:" +
" unexpected token [" + getTokenErrorDisplay(token) + "]" +
" was expecting one of [" + recognizer.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
ParseException parseException = new ParseException(message, token.getStartIndex());
throw new RuntimeException(parseException);
}
@Override
public void sync(Parser recognizer) {
}
}

View File

@ -0,0 +1,390 @@
// ANTLR GENERATED CODE: DO NOT EDIT
package org.elasticsearch.plan.a;
import java.util.Set;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
class PlanALexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
WS=1, COMMENT=2, LBRACK=3, RBRACK=4, LBRACE=5, RBRACE=6, LP=7, RP=8, DOT=9,
COMMA=10, SEMICOLON=11, IF=12, ELSE=13, WHILE=14, DO=15, FOR=16, CONTINUE=17,
BREAK=18, RETURN=19, NEW=20, TRY=21, CATCH=22, THROW=23, BOOLNOT=24, BWNOT=25,
MUL=26, DIV=27, REM=28, ADD=29, SUB=30, LSH=31, RSH=32, USH=33, LT=34,
LTE=35, GT=36, GTE=37, EQ=38, EQR=39, NE=40, NER=41, BWAND=42, BWXOR=43,
BWOR=44, BOOLAND=45, BOOLOR=46, COND=47, COLON=48, INCR=49, DECR=50, ASSIGN=51,
AADD=52, ASUB=53, AMUL=54, ADIV=55, AREM=56, AAND=57, AXOR=58, AOR=59,
ALSH=60, ARSH=61, AUSH=62, ACAT=63, OCTAL=64, HEX=65, INTEGER=66, DECIMAL=67,
STRING=68, CHAR=69, TRUE=70, FALSE=71, NULL=72, TYPE=73, ID=74, EXTINTEGER=75,
EXTID=76;
public static final int EXT = 1;
public static String[] modeNames = {
"DEFAULT_MODE", "EXT"
};
public static final String[] ruleNames = {
"WS", "COMMENT", "LBRACK", "RBRACK", "LBRACE", "RBRACE", "LP", "RP", "DOT",
"COMMA", "SEMICOLON", "IF", "ELSE", "WHILE", "DO", "FOR", "CONTINUE",
"BREAK", "RETURN", "NEW", "TRY", "CATCH", "THROW", "BOOLNOT", "BWNOT",
"MUL", "DIV", "REM", "ADD", "SUB", "LSH", "RSH", "USH", "LT", "LTE", "GT",
"GTE", "EQ", "EQR", "NE", "NER", "BWAND", "BWXOR", "BWOR", "BOOLAND",
"BOOLOR", "COND", "COLON", "INCR", "DECR", "ASSIGN", "AADD", "ASUB", "AMUL",
"ADIV", "AREM", "AAND", "AXOR", "AOR", "ALSH", "ARSH", "AUSH", "ACAT",
"OCTAL", "HEX", "INTEGER", "DECIMAL", "STRING", "CHAR", "TRUE", "FALSE",
"NULL", "TYPE", "GENERIC", "ID", "EXTINTEGER", "EXTID"
};
private static final String[] _LITERAL_NAMES = {
null, null, null, "'{'", "'}'", "'['", "']'", "'('", "')'", "'.'", "','",
"';'", "'if'", "'else'", "'while'", "'do'", "'for'", "'continue'", "'break'",
"'return'", "'new'", "'try'", "'catch'", "'throw'", "'!'", "'~'", "'*'",
"'/'", "'%'", "'+'", "'-'", "'<<'", "'>>'", "'>>>'", "'<'", "'<='", "'>'",
"'>='", "'=='", "'==='", "'!='", "'!=='", "'&'", "'^'", "'|'", "'&&'",
"'||'", "'?'", "':'", "'++'", "'--'", "'='", "'+='", "'-='", "'*='", "'/='",
"'%='", "'&='", "'^='", "'|='", "'<<='", "'>>='", "'>>>='", "'..='", null,
null, null, null, null, null, "'true'", "'false'", "'null'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, "WS", "COMMENT", "LBRACK", "RBRACK", "LBRACE", "RBRACE", "LP", "RP",
"DOT", "COMMA", "SEMICOLON", "IF", "ELSE", "WHILE", "DO", "FOR", "CONTINUE",
"BREAK", "RETURN", "NEW", "TRY", "CATCH", "THROW", "BOOLNOT", "BWNOT",
"MUL", "DIV", "REM", "ADD", "SUB", "LSH", "RSH", "USH", "LT", "LTE", "GT",
"GTE", "EQ", "EQR", "NE", "NER", "BWAND", "BWXOR", "BWOR", "BOOLAND",
"BOOLOR", "COND", "COLON", "INCR", "DECR", "ASSIGN", "AADD", "ASUB", "AMUL",
"ADIV", "AREM", "AAND", "AXOR", "AOR", "ALSH", "ARSH", "AUSH", "ACAT",
"OCTAL", "HEX", "INTEGER", "DECIMAL", "STRING", "CHAR", "TRUE", "FALSE",
"NULL", "TYPE", "ID", "EXTINTEGER", "EXTID"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
private Set<String> types = null;
void setTypes(Set<String> types) {
this.types = types;
}
public PlanALexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "PlanALexer.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
@Override
public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
switch (ruleIndex) {
case 67:
STRING_action((RuleContext)_localctx, actionIndex);
break;
case 68:
CHAR_action((RuleContext)_localctx, actionIndex);
break;
case 72:
TYPE_action((RuleContext)_localctx, actionIndex);
break;
}
}
private void STRING_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 0:
setText(getText().substring(1, getText().length() - 1));
break;
}
}
private void CHAR_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 1:
setText(getText().substring(1, getText().length() - 1));
break;
}
}
private void TYPE_action(RuleContext _localctx, int actionIndex) {
switch (actionIndex) {
case 2:
setText(getText().replace(" ", ""));
break;
}
}
@Override
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
case 72:
return TYPE_sempred((RuleContext)_localctx, predIndex);
}
return true;
}
private boolean TYPE_sempred(RuleContext _localctx, int predIndex) {
switch (predIndex) {
case 0:
return types.contains(getText().replace(" ", ""));
}
return true;
}
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2N\u0236\b\1\b\1\4"+
"\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n"+
"\4\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22"+
"\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31"+
"\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t"+
" \4!\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4\'\t\'\4(\t(\4)\t)\4*\t*\4+\t"+
"+\4,\t,\4-\t-\4.\t.\4/\t/\4\60\t\60\4\61\t\61\4\62\t\62\4\63\t\63\4\64"+
"\t\64\4\65\t\65\4\66\t\66\4\67\t\67\48\t8\49\t9\4:\t:\4;\t;\4<\t<\4=\t"+
"=\4>\t>\4?\t?\4@\t@\4A\tA\4B\tB\4C\tC\4D\tD\4E\tE\4F\tF\4G\tG\4H\tH\4"+
"I\tI\4J\tJ\4K\tK\4L\tL\4M\tM\4N\tN\3\2\6\2\u00a0\n\2\r\2\16\2\u00a1\3"+
"\2\3\2\3\3\3\3\3\3\3\3\7\3\u00aa\n\3\f\3\16\3\u00ad\13\3\3\3\3\3\3\3\3"+
"\3\3\3\7\3\u00b4\n\3\f\3\16\3\u00b7\13\3\3\3\3\3\5\3\u00bb\n\3\3\3\3\3"+
"\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\n\3\n\3\13"+
"\3\13\3\f\3\f\3\r\3\r\3\r\3\16\3\16\3\16\3\16\3\16\3\17\3\17\3\17\3\17"+
"\3\17\3\17\3\20\3\20\3\20\3\21\3\21\3\21\3\21\3\22\3\22\3\22\3\22\3\22"+
"\3\22\3\22\3\22\3\22\3\23\3\23\3\23\3\23\3\23\3\23\3\24\3\24\3\24\3\24"+
"\3\24\3\24\3\24\3\25\3\25\3\25\3\25\3\26\3\26\3\26\3\26\3\27\3\27\3\27"+
"\3\27\3\27\3\27\3\30\3\30\3\30\3\30\3\30\3\30\3\31\3\31\3\32\3\32\3\33"+
"\3\33\3\34\3\34\3\35\3\35\3\36\3\36\3\37\3\37\3 \3 \3 \3!\3!\3!\3\"\3"+
"\"\3\"\3\"\3#\3#\3$\3$\3$\3%\3%\3&\3&\3&\3\'\3\'\3\'\3(\3(\3(\3(\3)\3"+
")\3)\3*\3*\3*\3*\3+\3+\3,\3,\3-\3-\3.\3.\3.\3/\3/\3/\3\60\3\60\3\61\3"+
"\61\3\62\3\62\3\62\3\63\3\63\3\63\3\64\3\64\3\65\3\65\3\65\3\66\3\66\3"+
"\66\3\67\3\67\3\67\38\38\38\39\39\39\3:\3:\3:\3;\3;\3;\3<\3<\3<\3=\3="+
"\3=\3=\3>\3>\3>\3>\3?\3?\3?\3?\3?\3@\3@\3@\3@\3A\3A\6A\u0185\nA\rA\16"+
"A\u0186\3A\5A\u018a\nA\3B\3B\3B\6B\u018f\nB\rB\16B\u0190\3B\5B\u0194\n"+
"B\3C\3C\3C\7C\u0199\nC\fC\16C\u019c\13C\5C\u019e\nC\3C\5C\u01a1\nC\3D"+
"\3D\3D\7D\u01a6\nD\fD\16D\u01a9\13D\5D\u01ab\nD\3D\3D\7D\u01af\nD\fD\16"+
"D\u01b2\13D\3D\3D\5D\u01b6\nD\3D\6D\u01b9\nD\rD\16D\u01ba\5D\u01bd\nD"+
"\3D\5D\u01c0\nD\3E\3E\3E\3E\3E\3E\7E\u01c8\nE\fE\16E\u01cb\13E\3E\3E\3"+
"E\3F\3F\3F\3F\3F\3G\3G\3G\3G\3G\3H\3H\3H\3H\3H\3H\3I\3I\3I\3I\3I\3J\3"+
"J\5J\u01e7\nJ\3J\3J\3J\3K\7K\u01ed\nK\fK\16K\u01f0\13K\3K\3K\7K\u01f4"+
"\nK\fK\16K\u01f7\13K\3K\3K\5K\u01fb\nK\3K\7K\u01fe\nK\fK\16K\u0201\13"+
"K\3K\3K\7K\u0205\nK\fK\16K\u0208\13K\3K\3K\5K\u020c\nK\3K\7K\u020f\nK"+
"\fK\16K\u0212\13K\7K\u0214\nK\fK\16K\u0217\13K\3K\3K\3L\3L\7L\u021d\n"+
"L\fL\16L\u0220\13L\3M\3M\3M\7M\u0225\nM\fM\16M\u0228\13M\5M\u022a\nM\3"+
"M\3M\3N\3N\7N\u0230\nN\fN\16N\u0233\13N\3N\3N\5\u00ab\u00b5\u01c9\2O\4"+
"\3\6\4\b\5\n\6\f\7\16\b\20\t\22\n\24\13\26\f\30\r\32\16\34\17\36\20 \21"+
"\"\22$\23&\24(\25*\26,\27.\30\60\31\62\32\64\33\66\348\35:\36<\37> @!"+
"B\"D#F$H%J&L\'N(P)R*T+V,X-Z.\\/^\60`\61b\62d\63f\64h\65j\66l\67n8p9r:"+
"t;v<x=z>|?~@\u0080A\u0082B\u0084C\u0086D\u0088E\u008aF\u008cG\u008eH\u0090"+
"I\u0092J\u0094K\u0096\2\u0098L\u009aM\u009cN\4\2\3\21\5\2\13\f\17\17\""+
"\"\4\2\f\f\17\17\3\2\629\4\2NNnn\4\2ZZzz\5\2\62;CHch\3\2\63;\3\2\62;\b"+
"\2FFHHNNffhhnn\4\2GGgg\4\2--//\4\2HHhh\4\2$$^^\5\2C\\aac|\6\2\62;C\\a"+
"ac|\u0255\2\4\3\2\2\2\2\6\3\2\2\2\2\b\3\2\2\2\2\n\3\2\2\2\2\f\3\2\2\2"+
"\2\16\3\2\2\2\2\20\3\2\2\2\2\22\3\2\2\2\2\24\3\2\2\2\2\26\3\2\2\2\2\30"+
"\3\2\2\2\2\32\3\2\2\2\2\34\3\2\2\2\2\36\3\2\2\2\2 \3\2\2\2\2\"\3\2\2\2"+
"\2$\3\2\2\2\2&\3\2\2\2\2(\3\2\2\2\2*\3\2\2\2\2,\3\2\2\2\2.\3\2\2\2\2\60"+
"\3\2\2\2\2\62\3\2\2\2\2\64\3\2\2\2\2\66\3\2\2\2\28\3\2\2\2\2:\3\2\2\2"+
"\2<\3\2\2\2\2>\3\2\2\2\2@\3\2\2\2\2B\3\2\2\2\2D\3\2\2\2\2F\3\2\2\2\2H"+
"\3\2\2\2\2J\3\2\2\2\2L\3\2\2\2\2N\3\2\2\2\2P\3\2\2\2\2R\3\2\2\2\2T\3\2"+
"\2\2\2V\3\2\2\2\2X\3\2\2\2\2Z\3\2\2\2\2\\\3\2\2\2\2^\3\2\2\2\2`\3\2\2"+
"\2\2b\3\2\2\2\2d\3\2\2\2\2f\3\2\2\2\2h\3\2\2\2\2j\3\2\2\2\2l\3\2\2\2\2"+
"n\3\2\2\2\2p\3\2\2\2\2r\3\2\2\2\2t\3\2\2\2\2v\3\2\2\2\2x\3\2\2\2\2z\3"+
"\2\2\2\2|\3\2\2\2\2~\3\2\2\2\2\u0080\3\2\2\2\2\u0082\3\2\2\2\2\u0084\3"+
"\2\2\2\2\u0086\3\2\2\2\2\u0088\3\2\2\2\2\u008a\3\2\2\2\2\u008c\3\2\2\2"+
"\2\u008e\3\2\2\2\2\u0090\3\2\2\2\2\u0092\3\2\2\2\2\u0094\3\2\2\2\2\u0098"+
"\3\2\2\2\3\u009a\3\2\2\2\3\u009c\3\2\2\2\4\u009f\3\2\2\2\6\u00ba\3\2\2"+
"\2\b\u00be\3\2\2\2\n\u00c0\3\2\2\2\f\u00c2\3\2\2\2\16\u00c4\3\2\2\2\20"+
"\u00c6\3\2\2\2\22\u00c8\3\2\2\2\24\u00ca\3\2\2\2\26\u00ce\3\2\2\2\30\u00d0"+
"\3\2\2\2\32\u00d2\3\2\2\2\34\u00d5\3\2\2\2\36\u00da\3\2\2\2 \u00e0\3\2"+
"\2\2\"\u00e3\3\2\2\2$\u00e7\3\2\2\2&\u00f0\3\2\2\2(\u00f6\3\2\2\2*\u00fd"+
"\3\2\2\2,\u0101\3\2\2\2.\u0105\3\2\2\2\60\u010b\3\2\2\2\62\u0111\3\2\2"+
"\2\64\u0113\3\2\2\2\66\u0115\3\2\2\28\u0117\3\2\2\2:\u0119\3\2\2\2<\u011b"+
"\3\2\2\2>\u011d\3\2\2\2@\u011f\3\2\2\2B\u0122\3\2\2\2D\u0125\3\2\2\2F"+
"\u0129\3\2\2\2H\u012b\3\2\2\2J\u012e\3\2\2\2L\u0130\3\2\2\2N\u0133\3\2"+
"\2\2P\u0136\3\2\2\2R\u013a\3\2\2\2T\u013d\3\2\2\2V\u0141\3\2\2\2X\u0143"+
"\3\2\2\2Z\u0145\3\2\2\2\\\u0147\3\2\2\2^\u014a\3\2\2\2`\u014d\3\2\2\2"+
"b\u014f\3\2\2\2d\u0151\3\2\2\2f\u0154\3\2\2\2h\u0157\3\2\2\2j\u0159\3"+
"\2\2\2l\u015c\3\2\2\2n\u015f\3\2\2\2p\u0162\3\2\2\2r\u0165\3\2\2\2t\u0168"+
"\3\2\2\2v\u016b\3\2\2\2x\u016e\3\2\2\2z\u0171\3\2\2\2|\u0175\3\2\2\2~"+
"\u0179\3\2\2\2\u0080\u017e\3\2\2\2\u0082\u0182\3\2\2\2\u0084\u018b\3\2"+
"\2\2\u0086\u019d\3\2\2\2\u0088\u01aa\3\2\2\2\u008a\u01c1\3\2\2\2\u008c"+
"\u01cf\3\2\2\2\u008e\u01d4\3\2\2\2\u0090\u01d9\3\2\2\2\u0092\u01df\3\2"+
"\2\2\u0094\u01e4\3\2\2\2\u0096\u01ee\3\2\2\2\u0098\u021a\3\2\2\2\u009a"+
"\u0229\3\2\2\2\u009c\u022d\3\2\2\2\u009e\u00a0\t\2\2\2\u009f\u009e\3\2"+
"\2\2\u00a0\u00a1\3\2\2\2\u00a1\u009f\3\2\2\2\u00a1\u00a2\3\2\2\2\u00a2"+
"\u00a3\3\2\2\2\u00a3\u00a4\b\2\2\2\u00a4\5\3\2\2\2\u00a5\u00a6\7\61\2"+
"\2\u00a6\u00a7\7\61\2\2\u00a7\u00ab\3\2\2\2\u00a8\u00aa\13\2\2\2\u00a9"+
"\u00a8\3\2\2\2\u00aa\u00ad\3\2\2\2\u00ab\u00ac\3\2\2\2\u00ab\u00a9\3\2"+
"\2\2\u00ac\u00ae\3\2\2\2\u00ad\u00ab\3\2\2\2\u00ae\u00bb\t\3\2\2\u00af"+
"\u00b0\7\61\2\2\u00b0\u00b1\7,\2\2\u00b1\u00b5\3\2\2\2\u00b2\u00b4\13"+
"\2\2\2\u00b3\u00b2\3\2\2\2\u00b4\u00b7\3\2\2\2\u00b5\u00b6\3\2\2\2\u00b5"+
"\u00b3\3\2\2\2\u00b6\u00b8\3\2\2\2\u00b7\u00b5\3\2\2\2\u00b8\u00b9\7,"+
"\2\2\u00b9\u00bb\7\61\2\2\u00ba\u00a5\3\2\2\2\u00ba\u00af\3\2\2\2\u00bb"+
"\u00bc\3\2\2\2\u00bc\u00bd\b\3\2\2\u00bd\7\3\2\2\2\u00be\u00bf\7}\2\2"+
"\u00bf\t\3\2\2\2\u00c0\u00c1\7\177\2\2\u00c1\13\3\2\2\2\u00c2\u00c3\7"+
"]\2\2\u00c3\r\3\2\2\2\u00c4\u00c5\7_\2\2\u00c5\17\3\2\2\2\u00c6\u00c7"+
"\7*\2\2\u00c7\21\3\2\2\2\u00c8\u00c9\7+\2\2\u00c9\23\3\2\2\2\u00ca\u00cb"+
"\7\60\2\2\u00cb\u00cc\3\2\2\2\u00cc\u00cd\b\n\3\2\u00cd\25\3\2\2\2\u00ce"+
"\u00cf\7.\2\2\u00cf\27\3\2\2\2\u00d0\u00d1\7=\2\2\u00d1\31\3\2\2\2\u00d2"+
"\u00d3\7k\2\2\u00d3\u00d4\7h\2\2\u00d4\33\3\2\2\2\u00d5\u00d6\7g\2\2\u00d6"+
"\u00d7\7n\2\2\u00d7\u00d8\7u\2\2\u00d8\u00d9\7g\2\2\u00d9\35\3\2\2\2\u00da"+
"\u00db\7y\2\2\u00db\u00dc\7j\2\2\u00dc\u00dd\7k\2\2\u00dd\u00de\7n\2\2"+
"\u00de\u00df\7g\2\2\u00df\37\3\2\2\2\u00e0\u00e1\7f\2\2\u00e1\u00e2\7"+
"q\2\2\u00e2!\3\2\2\2\u00e3\u00e4\7h\2\2\u00e4\u00e5\7q\2\2\u00e5\u00e6"+
"\7t\2\2\u00e6#\3\2\2\2\u00e7\u00e8\7e\2\2\u00e8\u00e9\7q\2\2\u00e9\u00ea"+
"\7p\2\2\u00ea\u00eb\7v\2\2\u00eb\u00ec\7k\2\2\u00ec\u00ed\7p\2\2\u00ed"+
"\u00ee\7w\2\2\u00ee\u00ef\7g\2\2\u00ef%\3\2\2\2\u00f0\u00f1\7d\2\2\u00f1"+
"\u00f2\7t\2\2\u00f2\u00f3\7g\2\2\u00f3\u00f4\7c\2\2\u00f4\u00f5\7m\2\2"+
"\u00f5\'\3\2\2\2\u00f6\u00f7\7t\2\2\u00f7\u00f8\7g\2\2\u00f8\u00f9\7v"+
"\2\2\u00f9\u00fa\7w\2\2\u00fa\u00fb\7t\2\2\u00fb\u00fc\7p\2\2\u00fc)\3"+
"\2\2\2\u00fd\u00fe\7p\2\2\u00fe\u00ff\7g\2\2\u00ff\u0100\7y\2\2\u0100"+
"+\3\2\2\2\u0101\u0102\7v\2\2\u0102\u0103\7t\2\2\u0103\u0104\7{\2\2\u0104"+
"-\3\2\2\2\u0105\u0106\7e\2\2\u0106\u0107\7c\2\2\u0107\u0108\7v\2\2\u0108"+
"\u0109\7e\2\2\u0109\u010a\7j\2\2\u010a/\3\2\2\2\u010b\u010c\7v\2\2\u010c"+
"\u010d\7j\2\2\u010d\u010e\7t\2\2\u010e\u010f\7q\2\2\u010f\u0110\7y\2\2"+
"\u0110\61\3\2\2\2\u0111\u0112\7#\2\2\u0112\63\3\2\2\2\u0113\u0114\7\u0080"+
"\2\2\u0114\65\3\2\2\2\u0115\u0116\7,\2\2\u0116\67\3\2\2\2\u0117\u0118"+
"\7\61\2\2\u01189\3\2\2\2\u0119\u011a\7\'\2\2\u011a;\3\2\2\2\u011b\u011c"+
"\7-\2\2\u011c=\3\2\2\2\u011d\u011e\7/\2\2\u011e?\3\2\2\2\u011f\u0120\7"+
">\2\2\u0120\u0121\7>\2\2\u0121A\3\2\2\2\u0122\u0123\7@\2\2\u0123\u0124"+
"\7@\2\2\u0124C\3\2\2\2\u0125\u0126\7@\2\2\u0126\u0127\7@\2\2\u0127\u0128"+
"\7@\2\2\u0128E\3\2\2\2\u0129\u012a\7>\2\2\u012aG\3\2\2\2\u012b\u012c\7"+
">\2\2\u012c\u012d\7?\2\2\u012dI\3\2\2\2\u012e\u012f\7@\2\2\u012fK\3\2"+
"\2\2\u0130\u0131\7@\2\2\u0131\u0132\7?\2\2\u0132M\3\2\2\2\u0133\u0134"+
"\7?\2\2\u0134\u0135\7?\2\2\u0135O\3\2\2\2\u0136\u0137\7?\2\2\u0137\u0138"+
"\7?\2\2\u0138\u0139\7?\2\2\u0139Q\3\2\2\2\u013a\u013b\7#\2\2\u013b\u013c"+
"\7?\2\2\u013cS\3\2\2\2\u013d\u013e\7#\2\2\u013e\u013f\7?\2\2\u013f\u0140"+
"\7?\2\2\u0140U\3\2\2\2\u0141\u0142\7(\2\2\u0142W\3\2\2\2\u0143\u0144\7"+
"`\2\2\u0144Y\3\2\2\2\u0145\u0146\7~\2\2\u0146[\3\2\2\2\u0147\u0148\7("+
"\2\2\u0148\u0149\7(\2\2\u0149]\3\2\2\2\u014a\u014b\7~\2\2\u014b\u014c"+
"\7~\2\2\u014c_\3\2\2\2\u014d\u014e\7A\2\2\u014ea\3\2\2\2\u014f\u0150\7"+
"<\2\2\u0150c\3\2\2\2\u0151\u0152\7-\2\2\u0152\u0153\7-\2\2\u0153e\3\2"+
"\2\2\u0154\u0155\7/\2\2\u0155\u0156\7/\2\2\u0156g\3\2\2\2\u0157\u0158"+
"\7?\2\2\u0158i\3\2\2\2\u0159\u015a\7-\2\2\u015a\u015b\7?\2\2\u015bk\3"+
"\2\2\2\u015c\u015d\7/\2\2\u015d\u015e\7?\2\2\u015em\3\2\2\2\u015f\u0160"+
"\7,\2\2\u0160\u0161\7?\2\2\u0161o\3\2\2\2\u0162\u0163\7\61\2\2\u0163\u0164"+
"\7?\2\2\u0164q\3\2\2\2\u0165\u0166\7\'\2\2\u0166\u0167\7?\2\2\u0167s\3"+
"\2\2\2\u0168\u0169\7(\2\2\u0169\u016a\7?\2\2\u016au\3\2\2\2\u016b\u016c"+
"\7`\2\2\u016c\u016d\7?\2\2\u016dw\3\2\2\2\u016e\u016f\7~\2\2\u016f\u0170"+
"\7?\2\2\u0170y\3\2\2\2\u0171\u0172\7>\2\2\u0172\u0173\7>\2\2\u0173\u0174"+
"\7?\2\2\u0174{\3\2\2\2\u0175\u0176\7@\2\2\u0176\u0177\7@\2\2\u0177\u0178"+
"\7?\2\2\u0178}\3\2\2\2\u0179\u017a\7@\2\2\u017a\u017b\7@\2\2\u017b\u017c"+
"\7@\2\2\u017c\u017d\7?\2\2\u017d\177\3\2\2\2\u017e\u017f\7\60\2\2\u017f"+
"\u0180\7\60\2\2\u0180\u0181\7?\2\2\u0181\u0081\3\2\2\2\u0182\u0184\7\62"+
"\2\2\u0183\u0185\t\4\2\2\u0184\u0183\3\2\2\2\u0185\u0186\3\2\2\2\u0186"+
"\u0184\3\2\2\2\u0186\u0187\3\2\2\2\u0187\u0189\3\2\2\2\u0188\u018a\t\5"+
"\2\2\u0189\u0188\3\2\2\2\u0189\u018a\3\2\2\2\u018a\u0083\3\2\2\2\u018b"+
"\u018c\7\62\2\2\u018c\u018e\t\6\2\2\u018d\u018f\t\7\2\2\u018e\u018d\3"+
"\2\2\2\u018f\u0190\3\2\2\2\u0190\u018e\3\2\2\2\u0190\u0191\3\2\2\2\u0191"+
"\u0193\3\2\2\2\u0192\u0194\t\5\2\2\u0193\u0192\3\2\2\2\u0193\u0194\3\2"+
"\2\2\u0194\u0085\3\2\2\2\u0195\u019e\7\62\2\2\u0196\u019a\t\b\2\2\u0197"+
"\u0199\t\t\2\2\u0198\u0197\3\2\2\2\u0199\u019c\3\2\2\2\u019a\u0198\3\2"+
"\2\2\u019a\u019b\3\2\2\2\u019b\u019e\3\2\2\2\u019c\u019a\3\2\2\2\u019d"+
"\u0195\3\2\2\2\u019d\u0196\3\2\2\2\u019e\u01a0\3\2\2\2\u019f\u01a1\t\n"+
"\2\2\u01a0\u019f\3\2\2\2\u01a0\u01a1\3\2\2\2\u01a1\u0087\3\2\2\2\u01a2"+
"\u01ab\7\62\2\2\u01a3\u01a7\t\b\2\2\u01a4\u01a6\t\t\2\2\u01a5\u01a4\3"+
"\2\2\2\u01a6\u01a9\3\2\2\2\u01a7\u01a5\3\2\2\2\u01a7\u01a8\3\2\2\2\u01a8"+
"\u01ab\3\2\2\2\u01a9\u01a7\3\2\2\2\u01aa\u01a2\3\2\2\2\u01aa\u01a3\3\2"+
"\2\2\u01ab\u01ac\3\2\2\2\u01ac\u01b0\5\24\n\2\u01ad\u01af\t\t\2\2\u01ae"+
"\u01ad\3\2\2\2\u01af\u01b2\3\2\2\2\u01b0\u01ae\3\2\2\2\u01b0\u01b1\3\2"+
"\2\2\u01b1\u01bc\3\2\2\2\u01b2\u01b0\3\2\2\2\u01b3\u01b5\t\13\2\2\u01b4"+
"\u01b6\t\f\2\2\u01b5\u01b4\3\2\2\2\u01b5\u01b6\3\2\2\2\u01b6\u01b8\3\2"+
"\2\2\u01b7\u01b9\t\t\2\2\u01b8\u01b7\3\2\2\2\u01b9\u01ba\3\2\2\2\u01ba"+
"\u01b8\3\2\2\2\u01ba\u01bb\3\2\2\2\u01bb\u01bd\3\2\2\2\u01bc\u01b3\3\2"+
"\2\2\u01bc\u01bd\3\2\2\2\u01bd\u01bf\3\2\2\2\u01be\u01c0\t\r\2\2\u01bf"+
"\u01be\3\2\2\2\u01bf\u01c0\3\2\2\2\u01c0\u0089\3\2\2\2\u01c1\u01c9\7$"+
"\2\2\u01c2\u01c3\7^\2\2\u01c3\u01c8\7$\2\2\u01c4\u01c5\7^\2\2\u01c5\u01c8"+
"\7^\2\2\u01c6\u01c8\n\16\2\2\u01c7\u01c2\3\2\2\2\u01c7\u01c4\3\2\2\2\u01c7"+
"\u01c6\3\2\2\2\u01c8\u01cb\3\2\2\2\u01c9\u01ca\3\2\2\2\u01c9\u01c7\3\2"+
"\2\2\u01ca\u01cc\3\2\2\2\u01cb\u01c9\3\2\2\2\u01cc\u01cd\7$\2\2\u01cd"+
"\u01ce\bE\4\2\u01ce\u008b\3\2\2\2\u01cf\u01d0\7)\2\2\u01d0\u01d1\13\2"+
"\2\2\u01d1\u01d2\7)\2\2\u01d2\u01d3\bF\5\2\u01d3\u008d\3\2\2\2\u01d4\u01d5"+
"\7v\2\2\u01d5\u01d6\7t\2\2\u01d6\u01d7\7w\2\2\u01d7\u01d8\7g\2\2\u01d8"+
"\u008f\3\2\2\2\u01d9\u01da\7h\2\2\u01da\u01db\7c\2\2\u01db\u01dc\7n\2"+
"\2\u01dc\u01dd\7u\2\2\u01dd\u01de\7g\2\2\u01de\u0091\3\2\2\2\u01df\u01e0"+
"\7p\2\2\u01e0\u01e1\7w\2\2\u01e1\u01e2\7n\2\2\u01e2\u01e3\7n\2\2\u01e3"+
"\u0093\3\2\2\2\u01e4\u01e6\5\u0098L\2\u01e5\u01e7\5\u0096K\2\u01e6\u01e5"+
"\3\2\2\2\u01e6\u01e7\3\2\2\2\u01e7\u01e8\3\2\2\2\u01e8\u01e9\6J\2\2\u01e9"+
"\u01ea\bJ\6\2\u01ea\u0095\3\2\2\2\u01eb\u01ed\7\"\2\2\u01ec\u01eb\3\2"+
"\2\2\u01ed\u01f0\3\2\2\2\u01ee\u01ec\3\2\2\2\u01ee\u01ef\3\2\2\2\u01ef"+
"\u01f1\3\2\2\2\u01f0\u01ee\3\2\2\2\u01f1\u01f5\7>\2\2\u01f2\u01f4\7\""+
"\2\2\u01f3\u01f2\3\2\2\2\u01f4\u01f7\3\2\2\2\u01f5\u01f3\3\2\2\2\u01f5"+
"\u01f6\3\2\2\2\u01f6\u01f8\3\2\2\2\u01f7\u01f5\3\2\2\2\u01f8\u01fa\5\u0098"+
"L\2\u01f9\u01fb\5\u0096K\2\u01fa\u01f9\3\2\2\2\u01fa\u01fb\3\2\2\2\u01fb"+
"\u01ff\3\2\2\2\u01fc\u01fe\7\"\2\2\u01fd\u01fc\3\2\2\2\u01fe\u0201\3\2"+
"\2\2\u01ff\u01fd\3\2\2\2\u01ff\u0200\3\2\2\2\u0200\u0215\3\2\2\2\u0201"+
"\u01ff\3\2\2\2\u0202\u0206\5\26\13\2\u0203\u0205\7\"\2\2\u0204\u0203\3"+
"\2\2\2\u0205\u0208\3\2\2\2\u0206\u0204\3\2\2\2\u0206\u0207\3\2\2\2\u0207"+
"\u0209\3\2\2\2\u0208\u0206\3\2\2\2\u0209\u020b\5\u0098L\2\u020a\u020c"+
"\5\u0096K\2\u020b\u020a\3\2\2\2\u020b\u020c\3\2\2\2\u020c\u0210\3\2\2"+
"\2\u020d\u020f\7\"\2\2\u020e\u020d\3\2\2\2\u020f\u0212\3\2\2\2\u0210\u020e"+
"\3\2\2\2\u0210\u0211\3\2\2\2\u0211\u0214\3\2\2\2\u0212\u0210\3\2\2\2\u0213"+
"\u0202\3\2\2\2\u0214\u0217\3\2\2\2\u0215\u0213\3\2\2\2\u0215\u0216\3\2"+
"\2\2\u0216\u0218\3\2\2\2\u0217\u0215\3\2\2\2\u0218\u0219\7@\2\2\u0219"+
"\u0097\3\2\2\2\u021a\u021e\t\17\2\2\u021b\u021d\t\20\2\2\u021c\u021b\3"+
"\2\2\2\u021d\u0220\3\2\2\2\u021e\u021c\3\2\2\2\u021e\u021f\3\2\2\2\u021f"+
"\u0099\3\2\2\2\u0220\u021e\3\2\2\2\u0221\u022a\7\62\2\2\u0222\u0226\t"+
"\b\2\2\u0223\u0225\t\t\2\2\u0224\u0223\3\2\2\2\u0225\u0228\3\2\2\2\u0226"+
"\u0224\3\2\2\2\u0226\u0227\3\2\2\2\u0227\u022a\3\2\2\2\u0228\u0226\3\2"+
"\2\2\u0229\u0221\3\2\2\2\u0229\u0222\3\2\2\2\u022a\u022b\3\2\2\2\u022b"+
"\u022c\bM\7\2\u022c\u009b\3\2\2\2\u022d\u0231\t\17\2\2\u022e\u0230\t\20"+
"\2\2\u022f\u022e\3\2\2\2\u0230\u0233\3\2\2\2\u0231\u022f\3\2\2\2\u0231"+
"\u0232\3\2\2\2\u0232\u0234\3\2\2\2\u0233\u0231\3\2\2\2\u0234\u0235\bN"+
"\7\2\u0235\u009d\3\2\2\2%\2\3\u00a1\u00ab\u00b5\u00ba\u0186\u0189\u0190"+
"\u0193\u019a\u019d\u01a0\u01a7\u01aa\u01b0\u01b5\u01ba\u01bc\u01bf\u01c7"+
"\u01c9\u01e6\u01ee\u01f5\u01fa\u01ff\u0206\u020b\u0210\u0215\u021e\u0226"+
"\u0229\u0231\b\b\2\2\4\3\2\3E\2\3F\3\3J\4\4\2\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,357 @@
// ANTLR GENERATED CODE: DO NOT EDIT
package org.elasticsearch.plan.a;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
/**
* This class provides an empty implementation of {@link PlanAParserVisitor},
* which can be extended to create a visitor which only needs to handle a subset
* of the available methods.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
class PlanAParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements PlanAParserVisitor<T> {
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitSource(PlanAParser.SourceContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitIf(PlanAParser.IfContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitWhile(PlanAParser.WhileContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDo(PlanAParser.DoContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitFor(PlanAParser.ForContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDecl(PlanAParser.DeclContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitContinue(PlanAParser.ContinueContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitBreak(PlanAParser.BreakContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitReturn(PlanAParser.ReturnContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitTry(PlanAParser.TryContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitThrow(PlanAParser.ThrowContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExpr(PlanAParser.ExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitMultiple(PlanAParser.MultipleContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitSingle(PlanAParser.SingleContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitEmpty(PlanAParser.EmptyContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitInitializer(PlanAParser.InitializerContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitAfterthought(PlanAParser.AfterthoughtContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDeclaration(PlanAParser.DeclarationContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDecltype(PlanAParser.DecltypeContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDeclvar(PlanAParser.DeclvarContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitComp(PlanAParser.CompContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitBool(PlanAParser.BoolContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitConditional(PlanAParser.ConditionalContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitAssignment(PlanAParser.AssignmentContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitFalse(PlanAParser.FalseContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitNumeric(PlanAParser.NumericContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitUnary(PlanAParser.UnaryContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitPrecedence(PlanAParser.PrecedenceContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitPreinc(PlanAParser.PreincContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitPostinc(PlanAParser.PostincContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitCast(PlanAParser.CastContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExternal(PlanAParser.ExternalContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitNull(PlanAParser.NullContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitBinary(PlanAParser.BinaryContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitChar(PlanAParser.CharContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitTrue(PlanAParser.TrueContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtstart(PlanAParser.ExtstartContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtprec(PlanAParser.ExtprecContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtcast(PlanAParser.ExtcastContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtbrace(PlanAParser.ExtbraceContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtdot(PlanAParser.ExtdotContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExttype(PlanAParser.ExttypeContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtcall(PlanAParser.ExtcallContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtvar(PlanAParser.ExtvarContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtfield(PlanAParser.ExtfieldContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtnew(PlanAParser.ExtnewContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitExtstring(PlanAParser.ExtstringContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitArguments(PlanAParser.ArgumentsContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitIncrement(PlanAParser.IncrementContext ctx) { return visitChildren(ctx); }
}

View File

@ -0,0 +1,336 @@
// ANTLR GENERATED CODE: DO NOT EDIT
package org.elasticsearch.plan.a;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
/**
* This interface defines a complete generic visitor for a parse tree produced
* by {@link PlanAParser}.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
interface PlanAParserVisitor<T> extends ParseTreeVisitor<T> {
/**
* Visit a parse tree produced by {@link PlanAParser#source}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitSource(PlanAParser.SourceContext ctx);
/**
* Visit a parse tree produced by the {@code if}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitIf(PlanAParser.IfContext ctx);
/**
* Visit a parse tree produced by the {@code while}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitWhile(PlanAParser.WhileContext ctx);
/**
* Visit a parse tree produced by the {@code do}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDo(PlanAParser.DoContext ctx);
/**
* Visit a parse tree produced by the {@code for}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitFor(PlanAParser.ForContext ctx);
/**
* Visit a parse tree produced by the {@code decl}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDecl(PlanAParser.DeclContext ctx);
/**
* Visit a parse tree produced by the {@code continue}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitContinue(PlanAParser.ContinueContext ctx);
/**
* Visit a parse tree produced by the {@code break}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitBreak(PlanAParser.BreakContext ctx);
/**
* Visit a parse tree produced by the {@code return}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitReturn(PlanAParser.ReturnContext ctx);
/**
* Visit a parse tree produced by the {@code try}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitTry(PlanAParser.TryContext ctx);
/**
* Visit a parse tree produced by the {@code throw}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitThrow(PlanAParser.ThrowContext ctx);
/**
* Visit a parse tree produced by the {@code expr}
* labeled alternative in {@link PlanAParser#statement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExpr(PlanAParser.ExprContext ctx);
/**
* Visit a parse tree produced by the {@code multiple}
* labeled alternative in {@link PlanAParser#block}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitMultiple(PlanAParser.MultipleContext ctx);
/**
* Visit a parse tree produced by the {@code single}
* labeled alternative in {@link PlanAParser#block}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitSingle(PlanAParser.SingleContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#empty}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitEmpty(PlanAParser.EmptyContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#initializer}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitInitializer(PlanAParser.InitializerContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#afterthought}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitAfterthought(PlanAParser.AfterthoughtContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#declaration}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDeclaration(PlanAParser.DeclarationContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#decltype}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDecltype(PlanAParser.DecltypeContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#declvar}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDeclvar(PlanAParser.DeclvarContext ctx);
/**
* Visit a parse tree produced by the {@code comp}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitComp(PlanAParser.CompContext ctx);
/**
* Visit a parse tree produced by the {@code bool}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitBool(PlanAParser.BoolContext ctx);
/**
* Visit a parse tree produced by the {@code conditional}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitConditional(PlanAParser.ConditionalContext ctx);
/**
* Visit a parse tree produced by the {@code assignment}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitAssignment(PlanAParser.AssignmentContext ctx);
/**
* Visit a parse tree produced by the {@code false}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitFalse(PlanAParser.FalseContext ctx);
/**
* Visit a parse tree produced by the {@code numeric}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitNumeric(PlanAParser.NumericContext ctx);
/**
* Visit a parse tree produced by the {@code unary}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitUnary(PlanAParser.UnaryContext ctx);
/**
* Visit a parse tree produced by the {@code precedence}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitPrecedence(PlanAParser.PrecedenceContext ctx);
/**
* Visit a parse tree produced by the {@code preinc}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitPreinc(PlanAParser.PreincContext ctx);
/**
* Visit a parse tree produced by the {@code postinc}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitPostinc(PlanAParser.PostincContext ctx);
/**
* Visit a parse tree produced by the {@code cast}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitCast(PlanAParser.CastContext ctx);
/**
* Visit a parse tree produced by the {@code external}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExternal(PlanAParser.ExternalContext ctx);
/**
* Visit a parse tree produced by the {@code null}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitNull(PlanAParser.NullContext ctx);
/**
* Visit a parse tree produced by the {@code binary}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitBinary(PlanAParser.BinaryContext ctx);
/**
* Visit a parse tree produced by the {@code char}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitChar(PlanAParser.CharContext ctx);
/**
* Visit a parse tree produced by the {@code true}
* labeled alternative in {@link PlanAParser#expression}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitTrue(PlanAParser.TrueContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extstart}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtstart(PlanAParser.ExtstartContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extprec}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtprec(PlanAParser.ExtprecContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extcast}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtcast(PlanAParser.ExtcastContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extbrace}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtbrace(PlanAParser.ExtbraceContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extdot}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtdot(PlanAParser.ExtdotContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#exttype}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExttype(PlanAParser.ExttypeContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extcall}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtcall(PlanAParser.ExtcallContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extvar}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtvar(PlanAParser.ExtvarContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extfield}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtfield(PlanAParser.ExtfieldContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extnew}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtnew(PlanAParser.ExtnewContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#extstring}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitExtstring(PlanAParser.ExtstringContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#arguments}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitArguments(PlanAParser.ArgumentsContext ctx);
/**
* Visit a parse tree produced by {@link PlanAParser#increment}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitIncrement(PlanAParser.IncrementContext ctx);
}

View File

@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptModule;
public final class PlanAPlugin extends Plugin {
@Override
public String name() {
return "lang-plan-a";
}
@Override
public String description() {
return "Plan A scripting language for Elasticsearch";
}
public void onModule(ScriptModule module) {
module.addScriptEngine(PlanAScriptEngineService.class);
}
}

View File

@ -0,0 +1,140 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.SpecialPermission;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.LeafSearchScript;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.SearchScript;
import org.elasticsearch.search.lookup.SearchLookup;
import java.io.IOException;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.Permissions;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.Map;
public class PlanAScriptEngineService extends AbstractComponent implements ScriptEngineService {
public static final String NAME = "plan-a";
// TODO: this should really be per-script since scripts do so many different things?
private static final CompilerSettings compilerSettings = new CompilerSettings();
public static final String NUMERIC_OVERFLOW = "plan-a.numeric_overflow";
// TODO: how should custom definitions be specified?
private Definition definition = null;
@Inject
public PlanAScriptEngineService(Settings settings) {
super(settings);
compilerSettings.setNumericOverflow(settings.getAsBoolean(NUMERIC_OVERFLOW, compilerSettings.getNumericOverflow()));
}
public void setDefinition(final Definition definition) {
this.definition = new Definition(definition);
}
@Override
public String[] types() {
return new String[] { NAME };
}
@Override
public String[] extensions() {
return new String[] { NAME };
}
@Override
public boolean sandboxed() {
return true;
}
// context used during compilation
private static final AccessControlContext COMPILATION_CONTEXT;
static {
Permissions none = new Permissions();
none.setReadOnly();
COMPILATION_CONTEXT = new AccessControlContext(new ProtectionDomain[] {
new ProtectionDomain(null, none)
});
}
@Override
public Object compile(String script) {
// check we ourselves are not being called by unprivileged code
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new SpecialPermission());
}
// create our loader (which loads compiled code with no permissions)
Compiler.Loader loader = AccessController.doPrivileged(new PrivilegedAction<Compiler.Loader>() {
@Override
public Compiler.Loader run() {
return new Compiler.Loader(getClass().getClassLoader());
}
});
// drop all permissions to actually compile the code itself
return AccessController.doPrivileged(new PrivilegedAction<Executable>() {
@Override
public Executable run() {
return Compiler.compile(loader, "something", script, definition, compilerSettings);
}
}, COMPILATION_CONTEXT);
}
@Override
public ExecutableScript executable(CompiledScript compiledScript, Map<String,Object> vars) {
return new ScriptImpl((Executable) compiledScript.compiled(), vars, null);
}
@Override
public SearchScript search(CompiledScript compiledScript, SearchLookup lookup, Map<String,Object> vars) {
return new SearchScript() {
@Override
public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException {
return new ScriptImpl((Executable) compiledScript.compiled(), vars, lookup.getLeafSearchLookup(context));
}
@Override
public boolean needsScores() {
return true; // TODO: maybe even do these different and more like expressions.
}
};
}
@Override
public void scriptRemoved(CompiledScript script) {
// nothing to do
}
@Override
public void close() throws IOException {
// nothing to do
}
}

View File

@ -0,0 +1,96 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.apache.lucene.search.Scorer;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.LeafSearchScript;
import org.elasticsearch.script.ScoreAccessor;
import org.elasticsearch.search.lookup.LeafSearchLookup;
import java.util.HashMap;
import java.util.Map;
final class ScriptImpl implements ExecutableScript, LeafSearchScript {
final Executable executable;
final Map<String,Object> variables;
final LeafSearchLookup lookup;
ScriptImpl(Executable executable, Map<String,Object> vars, LeafSearchLookup lookup) {
this.executable = executable;
this.lookup = lookup;
this.variables = new HashMap<>();
if (vars != null) {
variables.putAll(vars);
}
if (lookup != null) {
variables.putAll(lookup.asMap());
}
}
@Override
public void setNextVar(String name, Object value) {
variables.put(name, value);
}
@Override
public Object run() {
return executable.execute(variables);
}
@Override
public float runAsFloat() {
return ((Number) run()).floatValue();
}
@Override
public long runAsLong() {
return ((Number) run()).longValue();
}
@Override
public double runAsDouble() {
return ((Number) run()).doubleValue();
}
@Override
public Object unwrap(Object value) {
return value;
}
@Override
public void setScorer(Scorer scorer) {
variables.put("_score", new ScoreAccessor(scorer));
}
@Override
public void setDocument(int doc) {
if (lookup != null) {
lookup.setDocument(doc);
}
}
@Override
public void setSource(Map<String,Object> source) {
if (lookup != null) {
lookup.source().setSource(source);
}
}
}

View File

@ -0,0 +1,801 @@
package org.elasticsearch.plan.a;
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class Utility {
public static boolean NumberToboolean(final Number value) {
return value.longValue() != 0;
}
public static char NumberTochar(final Number value) {
return (char)value.intValue();
}
public static Boolean NumberToBoolean(final Number value) {
return value.longValue() != 0;
}
public static Byte NumberToByte(final Number value) {
return value == null ? null : value.byteValue();
}
public static Short NumberToShort(final Number value) {
return value == null ? null : value.shortValue();
}
public static Character NumberToCharacter(final Number value) {
return value == null ? null : (char)value.intValue();
}
public static Integer NumberToInteger(final Number value) {
return value == null ? null : value.intValue();
}
public static Long NumberToLong(final Number value) {
return value == null ? null : value.longValue();
}
public static Float NumberToFloat(final Number value) {
return value == null ? null : value.floatValue();
}
public static Double NumberToDouble(final Number value) {
return value == null ? null : value.doubleValue();
}
public static byte booleanTobyte(final boolean value) {
return (byte)(value ? 1 : 0);
}
public static short booleanToshort(final boolean value) {
return (short)(value ? 1 : 0);
}
public static char booleanTochar(final boolean value) {
return (char)(value ? 1 : 0);
}
public static int booleanToint(final boolean value) {
return value ? 1 : 0;
}
public static long booleanTolong(final boolean value) {
return value ? 1 : 0;
}
public static float booleanTofloat(final boolean value) {
return value ? 1 : 0;
}
public static double booleanTodouble(final boolean value) {
return value ? 1 : 0;
}
public static Integer booleanToInteger(final boolean value) {
return value ? 1 : 0;
}
public static byte BooleanTobyte(final Boolean value) {
return (byte)(value ? 1 : 0);
}
public static short BooleanToshort(final Boolean value) {
return (short)(value ? 1 : 0);
}
public static char BooleanTochar(final Boolean value) {
return (char)(value ? 1 : 0);
}
public static int BooleanToint(final Boolean value) {
return value ? 1 : 0;
}
public static long BooleanTolong(final Boolean value) {
return value ? 1 : 0;
}
public static float BooleanTofloat(final Boolean value) {
return value ? 1 : 0;
}
public static double BooleanTodouble(final Boolean value) {
return value ? 1 : 0;
}
public static Byte BooleanToByte(final Boolean value) {
return value == null ? null : (byte)(value ? 1 : 0);
}
public static Short BooleanToShort(final Boolean value) {
return value == null ? null : (short)(value ? 1 : 0);
}
public static Character BooleanToCharacter(final Boolean value) {
return value == null ? null : (char)(value ? 1 : 0);
}
public static Integer BooleanToInteger(final Boolean value) {
return value == null ? null : value ? 1 : 0;
}
public static Long BooleanToLong(final Boolean value) {
return value == null ? null : value ? 1L : 0L;
}
public static Float BooleanToFloat(final Boolean value) {
return value == null ? null : value ? 1F : 0F;
}
public static Double BooleanToDouble(final Boolean value) {
return value == null ? null : value ? 1D : 0D;
}
public static boolean byteToboolean(final byte value) {
return value != 0;
}
public static Short byteToShort(final byte value) {
return (short)value;
}
public static Character byteToCharacter(final byte value) {
return (char)(byte)value;
}
public static Integer byteToInteger(final byte value) {
return (int)value;
}
public static Long byteToLong(final byte value) {
return (long)value;
}
public static Float byteToFloat(final byte value) {
return (float)value;
}
public static Double byteToDouble(final byte value) {
return (double)value;
}
public static boolean ByteToboolean(final Byte value) {
return value != 0;
}
public static char ByteTochar(final Byte value) {
return (char)value.byteValue();
}
public static boolean shortToboolean(final short value) {
return value != 0;
}
public static Byte shortToByte(final short value) {
return (byte)value;
}
public static Character shortToCharacter(final short value) {
return (char)(short)value;
}
public static Integer shortToInteger(final short value) {
return (int)value;
}
public static Long shortToLong(final short value) {
return (long)value;
}
public static Float shortToFloat(final short value) {
return (float)value;
}
public static Double shortToDouble(final short value) {
return (double)value;
}
public static boolean ShortToboolean(final Short value) {
return value != 0;
}
public static char ShortTochar(final Short value) {
return (char)value.shortValue();
}
public static boolean charToboolean(final char value) {
return value != 0;
}
public static Byte charToByte(final char value) {
return (byte)value;
}
public static Short charToShort(final char value) {
return (short)value;
}
public static Integer charToInteger(final char value) {
return (int)value;
}
public static Long charToLong(final char value) {
return (long)value;
}
public static Float charToFloat(final char value) {
return (float)value;
}
public static Double charToDouble(final char value) {
return (double)value;
}
public static boolean CharacterToboolean(final Character value) {
return value != 0;
}
public static byte CharacterTobyte(final Character value) {
return (byte)value.charValue();
}
public static short CharacterToshort(final Character value) {
return (short)value.charValue();
}
public static int CharacterToint(final Character value) {
return (int)value;
}
public static long CharacterTolong(final Character value) {
return (long)value;
}
public static float CharacterTofloat(final Character value) {
return (float)value;
}
public static double CharacterTodouble(final Character value) {
return (double)value;
}
public static Boolean CharacterToBoolean(final Character value) {
return value == null ? null : value != 0;
}
public static Byte CharacterToByte(final Character value) {
return value == null ? null : (byte)value.charValue();
}
public static Short CharacterToShort(final Character value) {
return value == null ? null : (short)value.charValue();
}
public static Integer CharacterToInteger(final Character value) {
return value == null ? null : (int)value;
}
public static Long CharacterToLong(final Character value) {
return value == null ? null : (long)value;
}
public static Float CharacterToFloat(final Character value) {
return value == null ? null : (float)value;
}
public static Double CharacterToDouble(final Character value) {
return value == null ? null : (double)value;
}
public static boolean intToboolean(final int value) {
return value != 0;
}
public static Byte intToByte(final int value) {
return (byte)value;
}
public static Short intToShort(final int value) {
return (short)value;
}
public static Character intToCharacter(final int value) {
return (char)(int)value;
}
public static Long intToLong(final int value) {
return (long)value;
}
public static Float intToFloat(final int value) {
return (float)value;
}
public static Double intToDouble(final int value) {
return (double)value;
}
public static boolean IntegerToboolean(final Integer value) {
return value != 0;
}
public static char IntegerTochar(final Integer value) {
return (char)value.intValue();
}
public static boolean longToboolean(final long value) {
return value != 0;
}
public static Byte longToByte(final long value) {
return (byte)value;
}
public static Short longToShort(final long value) {
return (short)value;
}
public static Character longToCharacter(final long value) {
return (char)(long)value;
}
public static Integer longToInteger(final long value) {
return (int)value;
}
public static Float longToFloat(final long value) {
return (float)value;
}
public static Double longToDouble(final long value) {
return (double)value;
}
public static boolean LongToboolean(final Long value) {
return value != 0;
}
public static char LongTochar(final Long value) {
return (char)value.longValue();
}
public static boolean floatToboolean(final float value) {
return value != 0;
}
public static Byte floatToByte(final float value) {
return (byte)value;
}
public static Short floatToShort(final float value) {
return (short)value;
}
public static Character floatToCharacter(final float value) {
return (char)(float)value;
}
public static Integer floatToInteger(final float value) {
return (int)value;
}
public static Long floatToLong(final float value) {
return (long)value;
}
public static Double floatToDouble(final float value) {
return (double)value;
}
public static boolean FloatToboolean(final Float value) {
return value != 0;
}
public static char FloatTochar(final Float value) {
return (char)value.floatValue();
}
public static boolean doubleToboolean(final double value) {
return value != 0;
}
public static Byte doubleToByte(final double value) {
return (byte)value;
}
public static Short doubleToShort(final double value) {
return (short)value;
}
public static Character doubleToCharacter(final double value) {
return (char)(double)value;
}
public static Integer doubleToInteger(final double value) {
return (int)value;
}
public static Long doubleToLong(final double value) {
return (long)value;
}
public static Float doubleToFloat(final double value) {
return (float)value;
}
public static boolean DoubleToboolean(final Double value) {
return value != 0;
}
public static char DoubleTochar(final Double value) {
return (char)value.doubleValue();
}
// although divide by zero is guaranteed, the special overflow case is not caught.
// its not needed for remainder because it is not possible there.
// see https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.17.2
/**
* Integer divide without overflow
* @throws ArithmeticException on overflow or divide-by-zero
*/
public static int divideWithoutOverflow(int x, int y) {
if (x == Integer.MIN_VALUE && y == -1) {
throw new ArithmeticException("integer overflow");
}
return x / y;
}
/**
* Long divide without overflow
* @throws ArithmeticException on overflow or divide-by-zero
*/
public static long divideWithoutOverflow(long x, long y) {
if (x == Long.MIN_VALUE && y == -1L) {
throw new ArithmeticException("long overflow");
}
return x / y;
}
// byte, short, and char are promoted to int for normal operations,
// so the JDK exact methods are typically used, and the result has a wider range.
// but compound assignments and increment/decrement operators (e.g. byte b = Byte.MAX_VALUE; b++;)
// implicitly cast back to the original type: so these need to be checked against the original range.
/**
* Like {@link Math#toIntExact(long)} but for byte range.
*/
public static byte toByteExact(int value) {
byte s = (byte) value;
if (s != value) {
throw new ArithmeticException("byte overflow");
}
return s;
}
/**
* Like {@link Math#toIntExact(long)} but for byte range.
*/
public static byte toByteExact(long value) {
byte s = (byte) value;
if (s != value) {
throw new ArithmeticException("byte overflow");
}
return s;
}
/**
* Like {@link Math#toIntExact(long)} but for byte range.
*/
public static byte toByteWithoutOverflow(float value) {
if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
throw new ArithmeticException("byte overflow");
}
return (byte)value;
}
/**
* Like {@link Math#toIntExact(long)} but for byte range.
*/
public static byte toByteWithoutOverflow(double value) {
if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
throw new ArithmeticException("byte overflow");
}
return (byte)value;
}
/**
* Like {@link Math#toIntExact(long)} but for short range.
*/
public static short toShortExact(int value) {
short s = (short) value;
if (s != value) {
throw new ArithmeticException("short overflow");
}
return s;
}
/**
* Like {@link Math#toIntExact(long)} but for short range.
*/
public static short toShortExact(long value) {
short s = (short) value;
if (s != value) {
throw new ArithmeticException("short overflow");
}
return s;
}
/**
* Like {@link Math#toIntExact(long)} but for short range.
*/
public static short toShortWithoutOverflow(float value) {
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw new ArithmeticException("short overflow");
}
return (short)value;
}
/**
* Like {@link Math#toIntExact(long)} but for short range.
*/
public static short toShortExact(double value) {
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw new ArithmeticException("short overflow");
}
return (short)value;
}
/**
* Like {@link Math#toIntExact(long)} but for char range.
*/
public static char toCharExact(int value) {
char s = (char) value;
if (s != value) {
throw new ArithmeticException("char overflow");
}
return s;
}
/**
* Like {@link Math#toIntExact(long)} but for char range.
*/
public static char toCharExact(long value) {
char s = (char) value;
if (s != value) {
throw new ArithmeticException("char overflow");
}
return s;
}
/**
* Like {@link Math#toIntExact(long)} but for char range.
*/
public static char toCharWithoutOverflow(float value) {
if (value < Character.MIN_VALUE || value > Character.MAX_VALUE) {
throw new ArithmeticException("char overflow");
}
return (char)value;
}
/**
* Like {@link Math#toIntExact(long)} but for char range.
*/
public static char toCharWithoutOverflow(double value) {
if (value < Character.MIN_VALUE || value > Character.MAX_VALUE) {
throw new ArithmeticException("char overflow");
}
return (char)value;
}
/**
* Like {@link Math#toIntExact(long)} but for int range.
*/
public static int toIntWithoutOverflow(float value) {
if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
throw new ArithmeticException("int overflow");
}
return (int)value;
}
/**
* Like {@link Math#toIntExact(long)} but for int range.
*/
public static int toIntWithoutOverflow(double value) {
if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
throw new ArithmeticException("int overflow");
}
return (int)value;
}
/**
* Like {@link Math#toIntExact(long)} but for long range.
*/
public static long toLongExactWithoutOverflow(float value) {
if (value < Long.MIN_VALUE || value > Long.MAX_VALUE) {
throw new ArithmeticException("long overflow");
}
return (long)value;
}
/**
* Like {@link Math#toIntExact(long)} but for long range.
*/
public static float toLongExactWithoutOverflow(double value) {
if (value < Long.MIN_VALUE || value > Long.MAX_VALUE) {
throw new ArithmeticException("long overflow");
}
return (long)value;
}
/**
* Like {@link Math#toIntExact(long)} but for float range.
*/
public static float toFloatWithoutOverflow(double value) {
if (value < Float.MIN_VALUE || value > Float.MAX_VALUE) {
throw new ArithmeticException("float overflow");
}
return (float)value;
}
/**
* Checks for overflow, result is infinite but operands are finite
* @throws ArithmeticException if overflow occurred
*/
private static float checkInfFloat(float x, float y, float z) {
if (Float.isInfinite(z)) {
if (Float.isFinite(x) && Float.isFinite(y)) {
throw new ArithmeticException("float overflow");
}
}
return z;
}
/**
* Checks for NaN, result is NaN but operands are finite
* @throws ArithmeticException if overflow occurred
*/
private static float checkNaNFloat(float x, float y, float z) {
if (Float.isNaN(z)) {
if (Float.isFinite(x) && Float.isFinite(y)) {
throw new ArithmeticException("NaN");
}
}
return z;
}
/**
* Checks for NaN, result is infinite but operands are finite
* @throws ArithmeticException if overflow occurred
*/
private static double checkInfDouble(double x, double y, double z) {
if (Double.isInfinite(z)) {
if (Double.isFinite(x) && Double.isFinite(y)) {
throw new ArithmeticException("double overflow");
}
}
return z;
}
/**
* Checks for NaN, result is NaN but operands are finite
* @throws ArithmeticException if overflow occurred
*/
private static double checkNaNDouble(double x, double y, double z) {
if (Double.isNaN(z)) {
if (Double.isFinite(x) && Double.isFinite(y)) {
throw new ArithmeticException("NaN");
}
}
return z;
}
/**
* Adds two floats but throws {@code ArithmeticException}
* if the result overflows.
*/
public static float addWithoutOverflow(float x, float y) {
return checkInfFloat(x, y, x + y);
}
/**
* Adds two doubles but throws {@code ArithmeticException}
* if the result overflows.
*/
public static double addWithoutOverflow(double x, double y) {
return checkInfDouble(x, y, x + y);
}
/**
* Subtracts two floats but throws {@code ArithmeticException}
* if the result overflows.
*/
public static float subtractWithoutOverflow(float x, float y) {
return checkInfFloat(x, y, x - y);
}
/**
* Subtracts two doubles but throws {@code ArithmeticException}
* if the result overflows.
*/
public static double subtractWithoutOverflow(double x, double y) {
return checkInfDouble(x, y , x - y);
}
/**
* Multiplies two floats but throws {@code ArithmeticException}
* if the result overflows.
*/
public static float multiplyWithoutOverflow(float x, float y) {
return checkInfFloat(x, y, x * y);
}
/**
* Multiplies two doubles but throws {@code ArithmeticException}
* if the result overflows.
*/
public static double multiplyWithoutOverflow(double x, double y) {
return checkInfDouble(x, y, x * y);
}
/**
* Divides two floats but throws {@code ArithmeticException}
* if the result overflows, or would create NaN from finite
* inputs ({@code x == 0, y == 0})
*/
public static float divideWithoutOverflow(float x, float y) {
return checkNaNFloat(x, y, checkInfFloat(x, y, x / y));
}
/**
* Divides two doubles but throws {@code ArithmeticException}
* if the result overflows, or would create NaN from finite
* inputs ({@code x == 0, y == 0})
*/
public static double divideWithoutOverflow(double x, double y) {
return checkNaNDouble(x, y, checkInfDouble(x, y, x / y));
}
/**
* Takes remainder two floats but throws {@code ArithmeticException}
* if the result would create NaN from finite inputs ({@code y == 0})
*/
public static float remainderWithoutOverflow(float x, float y) {
return checkNaNFloat(x, y, x % y);
}
/**
* Divides two doubles but throws {@code ArithmeticException}
* if the result would create NaN from finite inputs ({@code y == 0})
*/
public static double remainderWithoutOverflow(double x, double y) {
return checkNaNDouble(x, y, x % y);
}
public static boolean checkEquals(final Object left, final Object right) {
if (left != null && right != null) {
return left.equals(right);
}
return left == null && right == null;
}
private Utility() {}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
grant {
// needed to generate runtime classes
permission java.lang.RuntimePermission "createClassLoader";
};

View File

@ -0,0 +1,199 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.HashMap;
import java.util.Map;
/** Tests for addition operator across all types */
//TODO: NaN/Inf/overflow/...
public class AdditionTests extends ScriptTestCase {
public void testInt() throws Exception {
assertEquals(1+1, exec("int x = 1; int y = 1; return x+y;"));
assertEquals(1+2, exec("int x = 1; int y = 2; return x+y;"));
assertEquals(5+10, exec("int x = 5; int y = 10; return x+y;"));
assertEquals(1+1+2, exec("int x = 1; int y = 1; int z = 2; return x+y+z;"));
assertEquals((1+1)+2, exec("int x = 1; int y = 1; int z = 2; return (x+y)+z;"));
assertEquals(1+(1+2), exec("int x = 1; int y = 1; int z = 2; return x+(y+z);"));
assertEquals(0+1, exec("int x = 0; int y = 1; return x+y;"));
assertEquals(1+0, exec("int x = 1; int y = 0; return x+y;"));
assertEquals(0+0, exec("int x = 0; int y = 0; return x+y;"));
assertEquals(0+0, exec("int x = 0; int y = 0; return x+y;"));
}
public void testIntConst() throws Exception {
assertEquals(1+1, exec("return 1+1;"));
assertEquals(1+2, exec("return 1+2;"));
assertEquals(5+10, exec("return 5+10;"));
assertEquals(1+1+2, exec("return 1+1+2;"));
assertEquals((1+1)+2, exec("return (1+1)+2;"));
assertEquals(1+(1+2), exec("return 1+(1+2);"));
assertEquals(0+1, exec("return 0+1;"));
assertEquals(1+0, exec("return 1+0;"));
assertEquals(0+0, exec("return 0+0;"));
}
public void testByte() throws Exception {
assertEquals((byte)1+(byte)1, exec("byte x = 1; byte y = 1; return x+y;"));
assertEquals((byte)1+(byte)2, exec("byte x = 1; byte y = 2; return x+y;"));
assertEquals((byte)5+(byte)10, exec("byte x = 5; byte y = 10; return x+y;"));
assertEquals((byte)1+(byte)1+(byte)2, exec("byte x = 1; byte y = 1; byte z = 2; return x+y+z;"));
assertEquals(((byte)1+(byte)1)+(byte)2, exec("byte x = 1; byte y = 1; byte z = 2; return (x+y)+z;"));
assertEquals((byte)1+((byte)1+(byte)2), exec("byte x = 1; byte y = 1; byte z = 2; return x+(y+z);"));
assertEquals((byte)0+(byte)1, exec("byte x = 0; byte y = 1; return x+y;"));
assertEquals((byte)1+(byte)0, exec("byte x = 1; byte y = 0; return x+y;"));
assertEquals((byte)0+(byte)0, exec("byte x = 0; byte y = 0; return x+y;"));
}
public void testByteConst() throws Exception {
assertEquals((byte)1+(byte)1, exec("return (byte)1+(byte)1;"));
assertEquals((byte)1+(byte)2, exec("return (byte)1+(byte)2;"));
assertEquals((byte)5+(byte)10, exec("return (byte)5+(byte)10;"));
assertEquals((byte)1+(byte)1+(byte)2, exec("return (byte)1+(byte)1+(byte)2;"));
assertEquals(((byte)1+(byte)1)+(byte)2, exec("return ((byte)1+(byte)1)+(byte)2;"));
assertEquals((byte)1+((byte)1+(byte)2), exec("return (byte)1+((byte)1+(byte)2);"));
assertEquals((byte)0+(byte)1, exec("return (byte)0+(byte)1;"));
assertEquals((byte)1+(byte)0, exec("return (byte)1+(byte)0;"));
assertEquals((byte)0+(byte)0, exec("return (byte)0+(byte)0;"));
}
public void testChar() throws Exception {
assertEquals((char)1+(char)1, exec("char x = 1; char y = 1; return x+y;"));
assertEquals((char)1+(char)2, exec("char x = 1; char y = 2; return x+y;"));
assertEquals((char)5+(char)10, exec("char x = 5; char y = 10; return x+y;"));
assertEquals((char)1+(char)1+(char)2, exec("char x = 1; char y = 1; char z = 2; return x+y+z;"));
assertEquals(((char)1+(char)1)+(char)2, exec("char x = 1; char y = 1; char z = 2; return (x+y)+z;"));
assertEquals((char)1+((char)1+(char)2), exec("char x = 1; char y = 1; char z = 2; return x+(y+z);"));
assertEquals((char)0+(char)1, exec("char x = 0; char y = 1; return x+y;"));
assertEquals((char)1+(char)0, exec("char x = 1; char y = 0; return x+y;"));
assertEquals((char)0+(char)0, exec("char x = 0; char y = 0; return x+y;"));
}
public void testCharConst() throws Exception {
assertEquals((char)1+(char)1, exec("return (char)1+(char)1;"));
assertEquals((char)1+(char)2, exec("return (char)1+(char)2;"));
assertEquals((char)5+(char)10, exec("return (char)5+(char)10;"));
assertEquals((char)1+(char)1+(char)2, exec("return (char)1+(char)1+(char)2;"));
assertEquals(((char)1+(char)1)+(char)2, exec("return ((char)1+(char)1)+(char)2;"));
assertEquals((char)1+((char)1+(char)2), exec("return (char)1+((char)1+(char)2);"));
assertEquals((char)0+(char)1, exec("return (char)0+(char)1;"));
assertEquals((char)1+(char)0, exec("return (char)1+(char)0;"));
assertEquals((char)0+(char)0, exec("return (char)0+(char)0;"));
}
public void testShort() throws Exception {
assertEquals((short)1+(short)1, exec("short x = 1; short y = 1; return x+y;"));
assertEquals((short)1+(short)2, exec("short x = 1; short y = 2; return x+y;"));
assertEquals((short)5+(short)10, exec("short x = 5; short y = 10; return x+y;"));
assertEquals((short)1+(short)1+(short)2, exec("short x = 1; short y = 1; short z = 2; return x+y+z;"));
assertEquals(((short)1+(short)1)+(short)2, exec("short x = 1; short y = 1; short z = 2; return (x+y)+z;"));
assertEquals((short)1+((short)1+(short)2), exec("short x = 1; short y = 1; short z = 2; return x+(y+z);"));
assertEquals((short)0+(short)1, exec("short x = 0; short y = 1; return x+y;"));
assertEquals((short)1+(short)0, exec("short x = 1; short y = 0; return x+y;"));
assertEquals((short)0+(short)0, exec("short x = 0; short y = 0; return x+y;"));
}
public void testShortConst() throws Exception {
assertEquals((short)1+(short)1, exec("return (short)1+(short)1;"));
assertEquals((short)1+(short)2, exec("return (short)1+(short)2;"));
assertEquals((short)5+(short)10, exec("return (short)5+(short)10;"));
assertEquals((short)1+(short)1+(short)2, exec("return (short)1+(short)1+(short)2;"));
assertEquals(((short)1+(short)1)+(short)2, exec("return ((short)1+(short)1)+(short)2;"));
assertEquals((short)1+((short)1+(short)2), exec("return (short)1+((short)1+(short)2);"));
assertEquals((short)0+(short)1, exec("return (short)0+(short)1;"));
assertEquals((short)1+(short)0, exec("return (short)1+(short)0;"));
assertEquals((short)0+(short)0, exec("return (short)0+(short)0;"));
}
public void testLong() throws Exception {
assertEquals(1L+1L, exec("long x = 1; long y = 1; return x+y;"));
assertEquals(1L+2L, exec("long x = 1; long y = 2; return x+y;"));
assertEquals(5L+10L, exec("long x = 5; long y = 10; return x+y;"));
assertEquals(1L+1L+2L, exec("long x = 1; long y = 1; long z = 2; return x+y+z;"));
assertEquals((1L+1L)+2L, exec("long x = 1; long y = 1; long z = 2; return (x+y)+z;"));
assertEquals(1L+(1L+2L), exec("long x = 1; long y = 1; long z = 2; return x+(y+z);"));
assertEquals(0L+1L, exec("long x = 0; long y = 1; return x+y;"));
assertEquals(1L+0L, exec("long x = 1; long y = 0; return x+y;"));
assertEquals(0L+0L, exec("long x = 0; long y = 0; return x+y;"));
}
public void testLongConst() throws Exception {
assertEquals(1L+1L, exec("return 1L+1L;"));
assertEquals(1L+2L, exec("return 1L+2L;"));
assertEquals(5L+10L, exec("return 5L+10L;"));
assertEquals(1L+1L+2L, exec("return 1L+1L+2L;"));
assertEquals((1L+1L)+2L, exec("return (1L+1L)+2L;"));
assertEquals(1L+(1L+2L), exec("return 1L+(1L+2L);"));
assertEquals(0L+1L, exec("return 0L+1L;"));
assertEquals(1L+0L, exec("return 1L+0L;"));
assertEquals(0L+0L, exec("return 0L+0L;"));
}
public void testFloat() throws Exception {
assertEquals(1F+1F, exec("float x = 1F; float y = 1F; return x+y;"));
assertEquals(1F+2F, exec("float x = 1F; float y = 2F; return x+y;"));
assertEquals(5F+10F, exec("float x = 5F; float y = 10F; return x+y;"));
assertEquals(1F+1F+2F, exec("float x = 1F; float y = 1F; float z = 2F; return x+y+z;"));
assertEquals((1F+1F)+2F, exec("float x = 1F; float y = 1F; float z = 2F; return (x+y)+z;"));
assertEquals((1F+1F)+2F, exec("float x = 1F; float y = 1F; float z = 2F; return x+(y+z);"));
assertEquals(0F+1F, exec("float x = 0F; float y = 1F; return x+y;"));
assertEquals(1F+0F, exec("float x = 1F; float y = 0F; return x+y;"));
assertEquals(0F+0F, exec("float x = 0F; float y = 0F; return x+y;"));
}
public void testFloatConst() throws Exception {
assertEquals(1F+1F, exec("return 1F+1F;"));
assertEquals(1F+2F, exec("return 1F+2F;"));
assertEquals(5F+10F, exec("return 5F+10F;"));
assertEquals(1F+1F+2F, exec("return 1F+1F+2F;"));
assertEquals((1F+1F)+2F, exec("return (1F+1F)+2F;"));
assertEquals(1F+(1F+2F), exec("return 1F+(1F+2F);"));
assertEquals(0F+1F, exec("return 0F+1F;"));
assertEquals(1F+0F, exec("return 1F+0F;"));
assertEquals(0F+0F, exec("return 0F+0F;"));
}
public void testDouble() throws Exception {
assertEquals(1.0+1.0, exec("double x = 1.0; double y = 1.0; return x+y;"));
assertEquals(1.0+2.0, exec("double x = 1.0; double y = 2.0; return x+y;"));
assertEquals(5.0+10.0, exec("double x = 5.0; double y = 10.0; return x+y;"));
assertEquals(1.0+1.0+2.0, exec("double x = 1.0; double y = 1.0; double z = 2.0; return x+y+z;"));
assertEquals((1.0+1.0)+2.0, exec("double x = 1.0; double y = 1.0; double z = 2.0; return (x+y)+z;"));
assertEquals(1.0+(1.0+2.0), exec("double x = 1.0; double y = 1.0; double z = 2.0; return x+(y+z);"));
assertEquals(0.0+1.0, exec("double x = 0.0; double y = 1.0; return x+y;"));
assertEquals(1.0+0.0, exec("double x = 1.0; double y = 0.0; return x+y;"));
assertEquals(0.0+0.0, exec("double x = 0.0; double y = 0.0; return x+y;"));
}
public void testDoubleConst() throws Exception {
assertEquals(1.0+1.0, exec("return 1.0+1.0;"));
assertEquals(1.0+2.0, exec("return 1.0+2.0;"));
assertEquals(5.0+10.0, exec("return 5.0+10.0;"));
assertEquals(1.0+1.0+2.0, exec("return 1.0+1.0+2.0;"));
assertEquals((1.0+1.0)+2.0, exec("return (1.0+1.0)+2.0;"));
assertEquals(1.0+(1.0+2.0), exec("return 1.0+(1.0+2.0);"));
assertEquals(0.0+1.0, exec("return 0.0+1.0;"));
assertEquals(1.0+0.0, exec("return 1.0+0.0;"));
assertEquals(0.0+0.0, exec("return 0.0+0.0;"));
}
}

View File

@ -0,0 +1,48 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/** Tests for and operator across all types */
public class AndTests extends ScriptTestCase {
public void testInt() throws Exception {
assertEquals(5 & 12, exec("int x = 5; int y = 12; return x & y;"));
assertEquals(5 & -12, exec("int x = 5; int y = -12; return x & y;"));
assertEquals(7 & 15 & 3, exec("int x = 7; int y = 15; int z = 3; return x & y & z;"));
}
public void testIntConst() throws Exception {
assertEquals(5 & 12, exec("return 5 & 12;"));
assertEquals(5 & -12, exec("return 5 & -12;"));
assertEquals(7 & 15 & 3, exec("return 7 & 15 & 3;"));
}
public void testLong() throws Exception {
assertEquals(5L & 12L, exec("long x = 5; long y = 12; return x & y;"));
assertEquals(5L & -12L, exec("long x = 5; long y = -12; return x & y;"));
assertEquals(7L & 15L & 3L, exec("long x = 7; long y = 15; long z = 3; return x & y & z;"));
}
public void testLongConst() throws Exception {
assertEquals(5L & 12L, exec("return 5L & 12L;"));
assertEquals(5L & -12L, exec("return 5L & -12L;"));
assertEquals(7L & 15L & 3L, exec("return 7L & 15L & 3L;"));
}
}

View File

@ -0,0 +1,126 @@
package org.elasticsearch.plan.a;
import java.util.Collections;
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class BasicExpressionTests extends ScriptTestCase {
/** simple tests returning a constant value */
public void testReturnConstant() {
assertEquals(5, exec("return 5;"));
assertEquals(7L, exec("return 7L;"));
assertEquals(7.0, exec("return 7.0;"));
assertEquals(32.0F, exec("return 32.0F;"));
assertEquals((byte)255, exec("return (byte)255;"));
assertEquals((short)5, exec("return (short)5;"));
assertEquals("string", exec("return \"string\";"));
assertEquals(true, exec("return true;"));
assertEquals(false, exec("return false;"));
assertNull(exec("return null;"));
}
public void testReturnConstantChar() {
assertEquals('x', exec("return 'x';"));
}
public void testConstantCharTruncation() {
assertEquals('蚠', exec("return (char)100000;"));
}
/** declaring variables for primitive types */
public void testDeclareVariable() {
assertEquals(5, exec("int i = 5; return i;"));
assertEquals(7L, exec("long l = 7; return l;"));
assertEquals(7.0, exec("double d = 7; return d;"));
assertEquals(32.0F, exec("float f = 32F; return f;"));
assertEquals((byte)255, exec("byte b = (byte)255; return b;"));
assertEquals((short)5, exec("short s = (short)5; return s;"));
assertEquals("string", exec("String s = \"string\"; return s;"));
assertEquals(true, exec("boolean v = true; return v;"));
assertEquals(false, exec("boolean v = false; return v;"));
}
public void testCast() {
assertEquals(1, exec("return (int)1.0;"));
assertEquals((byte)100, exec("double x = 100; return (byte)x;"));
assertEquals(3, exec(
"Map x = new HashMap();\n" +
"Object y = x;\n" +
"((Map)y).put(2, 3);\n" +
"return x.get(2);\n"));
}
public void testCat() {
assertEquals("aaabbb", exec("return \"aaa\" + \"bbb\";"));
assertEquals("aaabbb", exec("String aaa = \"aaa\", bbb = \"bbb\"; return aaa + bbb;"));
assertEquals("aaabbbbbbbbb", exec(
"String aaa = \"aaa\", bbb = \"bbb\"; int x;\n" +
"for (; x < 3; ++x) \n" +
" aaa += bbb;\n" +
"return aaa;"));
}
public void testComp() {
assertEquals(true, exec("return 2 < 3;"));
assertEquals(false, exec("int x = 4; char y = 2; return x < y;"));
assertEquals(true, exec("return 3 <= 3;"));
assertEquals(true, exec("int x = 3; char y = 3; return x <= y;"));
assertEquals(false, exec("return 2 > 3;"));
assertEquals(true, exec("int x = 4; long y = 2; return x > y;"));
assertEquals(false, exec("return 3 >= 4;"));
assertEquals(true, exec("double x = 3; float y = 3; return x >= y;"));
assertEquals(false, exec("return 3 == 4;"));
assertEquals(true, exec("double x = 3; float y = 3; return x == y;"));
assertEquals(true, exec("return 3 != 4;"));
assertEquals(false, exec("double x = 3; float y = 3; return x != y;"));
}
/**
* Test boxed objects in various places
*/
public void testBoxing() {
// return
assertEquals(4, exec("return input.get(\"x\");", Collections.singletonMap("x", 4)));
// assignment
assertEquals(4, exec("int y = (Integer)input.get(\"x\"); return y;", Collections.singletonMap("x", 4)));
// comparison
assertEquals(true, exec("return 5 > (Integer)input.get(\"x\");", Collections.singletonMap("x", 4)));
}
public void testBool() {
assertEquals(true, exec("return true && true;"));
assertEquals(false, exec("boolean a = true, b = false; return a && b;"));
assertEquals(true, exec("return true || true;"));
assertEquals(true, exec("boolean a = true, b = false; return a || b;"));
}
public void testConditional() {
assertEquals(1, exec("int x = 5; return x > 3 ? 1 : 0;"));
assertEquals(0, exec("String a = null; return a != null ? 1 : 0;"));
}
public void testPrecedence() {
assertEquals(2, exec("int x = 5; return (x+x)/x;"));
assertEquals(true, exec("boolean t = true, f = false; return t && (f || t);"));
}
}

View File

@ -0,0 +1,178 @@
package org.elasticsearch.plan.a;
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.HashMap;
import java.util.Map;
public class BasicStatementTests extends ScriptTestCase {
public void testIfStatement() {
assertEquals(1, exec("int x = 5; if (x == 5) return 1; return 0;"));
assertEquals(0, exec("int x = 4; if (x == 5) return 1; else return 0;"));
assertEquals(2, exec("int x = 4; if (x == 5) return 1; else if (x == 4) return 2; else return 0;"));
assertEquals(1, exec("int x = 4; if (x == 5) return 1; else if (x == 4) return 1; else return 0;"));
assertEquals(3, exec(
"int x = 5;\n" +
"if (x == 5) {\n" +
" int y = 2;\n" +
" \n" +
" if (y == 2) {\n" +
" x = 3;\n" +
" }\n" +
" \n" +
"}\n" +
"\n" +
"return x;\n"));
}
public void testWhileStatement() {
assertEquals("aaaaaa", exec("String c = \"a\"; int x; while (x < 5) { c += \"a\"; ++x; } return c;"));
Object value = exec(
" byte[][] b = new byte[5][5]; \n" +
" byte x = 0, y; \n" +
" \n" +
" while (x < 5) { \n" +
" y = 0; \n" +
" \n" +
" while (y < 5) { \n" +
" b[x][y] = (byte)(x*y); \n" +
" ++y; \n" +
" } \n" +
" \n" +
" ++x; \n" +
" } \n" +
" \n" +
" return b; \n");
byte[][] b = (byte[][])value;
for (byte x = 0; x < 5; ++x) {
for (byte y = 0; y < 5; ++y) {
assertEquals(x*y, b[x][y]);
}
}
}
public void testDoWhileStatement() {
assertEquals("aaaaaa", exec("String c = \"a\"; int x; do { c += \"a\"; ++x; } while (x < 5); return c;"));
Object value = exec(
" int[][] b = new int[5][5]; \n" +
" int x = 0, y; \n" +
" \n" +
" do { \n" +
" y = 0; \n" +
" \n" +
" do { \n" +
" b[x][y] = x*y; \n" +
" ++y; \n" +
" } while (y < 5); \n" +
" \n" +
" ++x; \n" +
" } while (x < 5); \n" +
" \n" +
" return b; \n");
int[][] b = (int[][])value;
for (byte x = 0; x < 5; ++x) {
for (byte y = 0; y < 5; ++y) {
assertEquals(x*y, b[x][y]);
}
}
}
public void testForStatement() {
assertEquals("aaaaaa", exec("String c = \"a\"; for (int x = 0; x < 5; ++x) c += \"a\"; return c;"));
Object value = exec(
" int[][] b = new int[5][5]; \n" +
" for (int x = 0; x < 5; ++x) { \n" +
" for (int y = 0; y < 5; ++y) { \n" +
" b[x][y] = x*y; \n" +
" } \n" +
" } \n" +
" \n" +
" return b; \n");
int[][] b = (int[][])value;
for (byte x = 0; x < 5; ++x) {
for (byte y = 0; y < 5; ++y) {
assertEquals(x*y, b[x][y]);
}
}
}
public void testDeclarationStatement() {
assertEquals((byte)2, exec("byte a = 2; return a;"));
assertEquals((short)2, exec("short a = 2; return a;"));
assertEquals((char)2, exec("char a = 2; return a;"));
assertEquals(2, exec("int a = 2; return a;"));
assertEquals(2L, exec("long a = 2; return a;"));
assertEquals(2F, exec("float a = 2; return a;"));
assertEquals(2.0, exec("double a = 2; return a;"));
assertEquals(false, exec("boolean a = false; return a;"));
assertEquals("string", exec("String a = \"string\"; return a;"));
assertEquals(HashMap.class, exec("Map<String,Object> a = new HashMap<String,Object>(); return a;").getClass());
assertEquals(byte[].class, exec("byte[] a = new byte[1]; return a;").getClass());
assertEquals(short[].class, exec("short[] a = new short[1]; return a;").getClass());
assertEquals(char[].class, exec("char[] a = new char[1]; return a;").getClass());
assertEquals(int[].class, exec("int[] a = new int[1]; return a;").getClass());
assertEquals(long[].class, exec("long[] a = new long[1]; return a;").getClass());
assertEquals(float[].class, exec("float[] a = new float[1]; return a;").getClass());
assertEquals(double[].class, exec("double[] a = new double[1]; return a;").getClass());
assertEquals(boolean[].class, exec("boolean[] a = new boolean[1]; return a;").getClass());
assertEquals(String[].class, exec("String[] a = new String[1]; return a;").getClass());
assertEquals(Map[].class, exec("Map<String,Object>[] a = new Map<String,Object>[1]; return a;").getClass());
assertEquals(byte[][].class, exec("byte[][] a = new byte[1][2]; return a;").getClass());
assertEquals(short[][][].class, exec("short[][][] a = new short[1][2][3]; return a;").getClass());
assertEquals(char[][][][].class, exec("char[][][][] a = new char[1][2][3][4]; return a;").getClass());
assertEquals(int[][][][][].class, exec("int[][][][][] a = new int[1][2][3][4][5]; return a;").getClass());
assertEquals(long[][].class, exec("long[][] a = new long[1][2]; return a;").getClass());
assertEquals(float[][][].class, exec("float[][][] a = new float[1][2][3]; return a;").getClass());
assertEquals(double[][][][].class, exec("double[][][][] a = new double[1][2][3][4]; return a;").getClass());
assertEquals(boolean[][][][][].class, exec("boolean[][][][][] a = new boolean[1][2][3][4][5]; return a;").getClass());
assertEquals(String[][].class, exec("String[][] a = new String[1][2]; return a;").getClass());
assertEquals(Map[][][].class, exec("Map<String,Object>[][][] a = new Map<String,Object>[1][2][3]; return a;").getClass());
}
public void testContinueStatement() {
assertEquals(9, exec("int x = 0, y = 0; while (x < 10) { ++x; if (x == 1) continue; ++y; } return y;"));
}
public void testBreakStatement() {
assertEquals(4, exec("int x = 0, y = 0; while (x < 10) { ++x; if (x == 5) break; ++y; } return y;"));
}
public void testReturnStatement() {
assertEquals(10, exec("return 10;"));
assertEquals(5, exec("int x = 5; return x;"));
assertEquals(4, exec("int[] x = new int[2]; x[1] = 4; return x[1];"));
assertEquals(5, ((short[])exec("short[] s = new short[3]; s[1] = 5; return s;"))[1]);
assertEquals(10, ((Map)exec("Map<String, Object> s = new HashMap< String , Object >(); s.put(\"x\", 10); return s;")).get("x"));
}
}

View File

@ -0,0 +1,294 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/**
* Tests binary operators across different types
*/
// TODO: NaN/Inf/overflow/...
public class BinaryOperatorTests extends ScriptTestCase {
// TODO: move to per-type tests and test for each type
public void testBasics() {
assertEquals(2.25F / 1.5F, exec("return 2.25F / 1.5F;"));
assertEquals(2.25F % 1.5F, exec("return 2.25F % 1.5F;"));
assertEquals(2 - 1, exec("return 2 - 1;"));
assertEquals(1 << 2, exec("return 1 << 2;"));
assertEquals(4 >> 2, exec("return 4 >> 2;"));
assertEquals(-1 >>> 29, exec("return -1 >>> 29;"));
assertEquals(5 & 3, exec("return 5 & 3;"));
assertEquals(5 & 3L, exec("return 5 & 3L;"));
assertEquals(5L & 3, exec("return 5L & 3;"));
assertEquals(5 | 3, exec("return 5 | 3;"));
assertEquals(5L | 3, exec("return 5L | 3;"));
assertEquals(5 | 3L, exec("return 5 | 3L;"));
assertEquals(9 ^ 3, exec("return 9 ^ 3;"));
assertEquals(9L ^ 3, exec("return 9L ^ 3;"));
assertEquals(9 ^ 3L, exec("return 9 ^ 3L;"));
}
public void testLongShifts() {
// note: we always promote the results of shifts too (unlike java)
assertEquals(1L << 2, exec("long x = 1L; int y = 2; return x << y;"));
assertEquals(1L << 2L, exec("long x = 1L; long y = 2L; return x << y;"));
assertEquals(4L >> 2L, exec("long x = 4L; long y = 2L; return x >> y;"));
assertEquals(4L >> 2, exec("long x = 4L; int y = 2; return x >> y;"));
assertEquals(-1L >>> 29, exec("long x = -1L; int y = 29; return x >>> y;"));
assertEquals(-1L >>> 29L, exec("long x = -1L; long y = 29L; return x >>> y;"));
}
public void testLongShiftsConst() {
// note: we always promote the results of shifts too (unlike java)
assertEquals(1L << 2, exec("return 1L << 2;"));
assertEquals(1L << 2L, exec("return 1 << 2L;"));
assertEquals(4L >> 2L, exec("return 4 >> 2L;"));
assertEquals(4L >> 2, exec("return 4L >> 2;"));
assertEquals(-1L >>> 29, exec("return -1L >>> 29;"));
assertEquals(-1L >>> 29L, exec("return -1 >>> 29L;"));
}
public void testMixedTypes() {
assertEquals(8, exec("int x = 4; char y = 2; return x*y;"));
assertEquals(0.5, exec("double x = 1; float y = 2; return x / y;"));
assertEquals(1, exec("int x = 3; int y = 2; return x % y;"));
assertEquals(3.0, exec("double x = 1; byte y = 2; return x + y;"));
assertEquals(-1, exec("int x = 1; char y = 2; return x - y;"));
assertEquals(4, exec("int x = 1; char y = 2; return x << y;"));
assertEquals(-1, exec("int x = -1; char y = 29; return x >> y;"));
assertEquals(3, exec("int x = -1; char y = 30; return x >>> y;"));
assertEquals(1L, exec("int x = 5; long y = 3; return x & y;"));
assertEquals(7, exec("short x = 5; byte y = 3; return x | y;"));
assertEquals(10, exec("short x = 9; char y = 3; return x ^ y;"));
}
public void testBinaryPromotion() throws Exception {
// byte/byte
assertEquals((byte)1 + (byte)1, exec("byte x = 1; byte y = 1; return x+y;"));
// byte/char
assertEquals((byte)1 + (char)1, exec("byte x = 1; char y = 1; return x+y;"));
// byte/short
assertEquals((byte)1 + (short)1, exec("byte x = 1; short y = 1; return x+y;"));
// byte/int
assertEquals((byte)1 + 1, exec("byte x = 1; int y = 1; return x+y;"));
// byte/long
assertEquals((byte)1 + 1L, exec("byte x = 1; long y = 1; return x+y;"));
// byte/float
assertEquals((byte)1 + 1F, exec("byte x = 1; float y = 1; return x+y;"));
// byte/double
assertEquals((byte)1 + 1.0, exec("byte x = 1; double y = 1; return x+y;"));
// char/byte
assertEquals((char)1 + (byte)1, exec("char x = 1; byte y = 1; return x+y;"));
// char/char
assertEquals((char)1 + (char)1, exec("char x = 1; char y = 1; return x+y;"));
// char/short
assertEquals((char)1 + (short)1, exec("char x = 1; short y = 1; return x+y;"));
// char/int
assertEquals((char)1 + 1, exec("char x = 1; int y = 1; return x+y;"));
// char/long
assertEquals((char)1 + 1L, exec("char x = 1; long y = 1; return x+y;"));
// char/float
assertEquals((char)1 + 1F, exec("char x = 1; float y = 1; return x+y;"));
// char/double
assertEquals((char)1 + 1.0, exec("char x = 1; double y = 1; return x+y;"));
// short/byte
assertEquals((short)1 + (byte)1, exec("short x = 1; byte y = 1; return x+y;"));
// short/char
assertEquals((short)1 + (char)1, exec("short x = 1; char y = 1; return x+y;"));
// short/short
assertEquals((short)1 + (short)1, exec("short x = 1; short y = 1; return x+y;"));
// short/int
assertEquals((short)1 + 1, exec("short x = 1; int y = 1; return x+y;"));
// short/long
assertEquals((short)1 + 1L, exec("short x = 1; long y = 1; return x+y;"));
// short/float
assertEquals((short)1 + 1F, exec("short x = 1; float y = 1; return x+y;"));
// short/double
assertEquals((short)1 + 1.0, exec("short x = 1; double y = 1; return x+y;"));
// int/byte
assertEquals(1 + (byte)1, exec("int x = 1; byte y = 1; return x+y;"));
// int/char
assertEquals(1 + (char)1, exec("int x = 1; char y = 1; return x+y;"));
// int/short
assertEquals(1 + (short)1, exec("int x = 1; short y = 1; return x+y;"));
// int/int
assertEquals(1 + 1, exec("int x = 1; int y = 1; return x+y;"));
// int/long
assertEquals(1 + 1L, exec("int x = 1; long y = 1; return x+y;"));
// int/float
assertEquals(1 + 1F, exec("int x = 1; float y = 1; return x+y;"));
// int/double
assertEquals(1 + 1.0, exec("int x = 1; double y = 1; return x+y;"));
// long/byte
assertEquals(1L + (byte)1, exec("long x = 1; byte y = 1; return x+y;"));
// long/char
assertEquals(1L + (char)1, exec("long x = 1; char y = 1; return x+y;"));
// long/short
assertEquals(1L + (short)1, exec("long x = 1; short y = 1; return x+y;"));
// long/int
assertEquals(1L + 1, exec("long x = 1; int y = 1; return x+y;"));
// long/long
assertEquals(1L + 1L, exec("long x = 1; long y = 1; return x+y;"));
// long/float
assertEquals(1L + 1F, exec("long x = 1; float y = 1; return x+y;"));
// long/double
assertEquals(1L + 1.0, exec("long x = 1; double y = 1; return x+y;"));
// float/byte
assertEquals(1F + (byte)1, exec("float x = 1; byte y = 1; return x+y;"));
// float/char
assertEquals(1F + (char)1, exec("float x = 1; char y = 1; return x+y;"));
// float/short
assertEquals(1F + (short)1, exec("float x = 1; short y = 1; return x+y;"));
// float/int
assertEquals(1F + 1, exec("float x = 1; int y = 1; return x+y;"));
// float/long
assertEquals(1F + 1L, exec("float x = 1; long y = 1; return x+y;"));
// float/float
assertEquals(1F + 1F, exec("float x = 1; float y = 1; return x+y;"));
// float/double
assertEquals(1F + 1.0, exec("float x = 1; double y = 1; return x+y;"));
// double/byte
assertEquals(1.0 + (byte)1, exec("double x = 1; byte y = 1; return x+y;"));
// double/char
assertEquals(1.0 + (char)1, exec("double x = 1; char y = 1; return x+y;"));
// double/short
assertEquals(1.0 + (short)1, exec("double x = 1; short y = 1; return x+y;"));
// double/int
assertEquals(1.0 + 1, exec("double x = 1; int y = 1; return x+y;"));
// double/long
assertEquals(1.0 + 1L, exec("double x = 1; long y = 1; return x+y;"));
// double/float
assertEquals(1.0 + 1F, exec("double x = 1; float y = 1; return x+y;"));
// double/double
assertEquals(1.0 + 1.0, exec("double x = 1; double y = 1; return x+y;"));
}
public void testBinaryPromotionConst() throws Exception {
// byte/byte
assertEquals((byte)1 + (byte)1, exec("return (byte)1 + (byte)1;"));
// byte/char
assertEquals((byte)1 + (char)1, exec("return (byte)1 + (char)1;"));
// byte/short
assertEquals((byte)1 + (short)1, exec("return (byte)1 + (short)1;"));
// byte/int
assertEquals((byte)1 + 1, exec("return (byte)1 + 1;"));
// byte/long
assertEquals((byte)1 + 1L, exec("return (byte)1 + 1L;"));
// byte/float
assertEquals((byte)1 + 1F, exec("return (byte)1 + 1F;"));
// byte/double
assertEquals((byte)1 + 1.0, exec("return (byte)1 + 1.0;"));
// char/byte
assertEquals((char)1 + (byte)1, exec("return (char)1 + (byte)1;"));
// char/char
assertEquals((char)1 + (char)1, exec("return (char)1 + (char)1;"));
// char/short
assertEquals((char)1 + (short)1, exec("return (char)1 + (short)1;"));
// char/int
assertEquals((char)1 + 1, exec("return (char)1 + 1;"));
// char/long
assertEquals((char)1 + 1L, exec("return (char)1 + 1L;"));
// char/float
assertEquals((char)1 + 1F, exec("return (char)1 + 1F;"));
// char/double
assertEquals((char)1 + 1.0, exec("return (char)1 + 1.0;"));
// short/byte
assertEquals((short)1 + (byte)1, exec("return (short)1 + (byte)1;"));
// short/char
assertEquals((short)1 + (char)1, exec("return (short)1 + (char)1;"));
// short/short
assertEquals((short)1 + (short)1, exec("return (short)1 + (short)1;"));
// short/int
assertEquals((short)1 + 1, exec("return (short)1 + 1;"));
// short/long
assertEquals((short)1 + 1L, exec("return (short)1 + 1L;"));
// short/float
assertEquals((short)1 + 1F, exec("return (short)1 + 1F;"));
// short/double
assertEquals((short)1 + 1.0, exec("return (short)1 + 1.0;"));
// int/byte
assertEquals(1 + (byte)1, exec("return 1 + (byte)1;"));
// int/char
assertEquals(1 + (char)1, exec("return 1 + (char)1;"));
// int/short
assertEquals(1 + (short)1, exec("return 1 + (short)1;"));
// int/int
assertEquals(1 + 1, exec("return 1 + 1;"));
// int/long
assertEquals(1 + 1L, exec("return 1 + 1L;"));
// int/float
assertEquals(1 + 1F, exec("return 1 + 1F;"));
// int/double
assertEquals(1 + 1.0, exec("return 1 + 1.0;"));
// long/byte
assertEquals(1L + (byte)1, exec("return 1L + (byte)1;"));
// long/char
assertEquals(1L + (char)1, exec("return 1L + (char)1;"));
// long/short
assertEquals(1L + (short)1, exec("return 1L + (short)1;"));
// long/int
assertEquals(1L + 1, exec("return 1L + 1;"));
// long/long
assertEquals(1L + 1L, exec("return 1L + 1L;"));
// long/float
assertEquals(1L + 1F, exec("return 1L + 1F;"));
// long/double
assertEquals(1L + 1.0, exec("return 1L + 1.0;"));
// float/byte
assertEquals(1F + (byte)1, exec("return 1F + (byte)1;"));
// float/char
assertEquals(1F + (char)1, exec("return 1F + (char)1;"));
// float/short
assertEquals(1F + (short)1, exec("return 1F + (short)1;"));
// float/int
assertEquals(1F + 1, exec("return 1F + 1;"));
// float/long
assertEquals(1F + 1L, exec("return 1F + 1L;"));
// float/float
assertEquals(1F + 1F, exec("return 1F + 1F;"));
// float/double
assertEquals(1F + 1.0, exec("return 1F + 1.0;"));
// double/byte
assertEquals(1.0 + (byte)1, exec("return 1.0 + (byte)1;"));
// double/char
assertEquals(1.0 + (char)1, exec("return 1.0 + (char)1;"));
// double/short
assertEquals(1.0 + (short)1, exec("return 1.0 + (short)1;"));
// double/int
assertEquals(1.0 + 1, exec("return 1.0 + 1;"));
// double/long
assertEquals(1.0 + 1L, exec("return 1.0 + 1L;"));
// double/float
assertEquals(1.0 + 1F, exec("return 1.0 + 1F;"));
// double/double
assertEquals(1.0 + 1.0, exec("return 1.0 + 1.0;"));
}
}

View File

@ -0,0 +1,319 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/**
* Tests compound assignments (+=, etc) across all data types
*/
public class CompoundAssignmentTests extends ScriptTestCase {
public void testAddition() {
// byte
assertEquals((byte) 15, exec("byte x = 5; x += 10; return x;"));
assertEquals((byte) -5, exec("byte x = 5; x += -10; return x;"));
// short
assertEquals((short) 15, exec("short x = 5; x += 10; return x;"));
assertEquals((short) -5, exec("short x = 5; x += -10; return x;"));
// char
assertEquals((char) 15, exec("char x = 5; x += 10; return x;"));
assertEquals((char) 5, exec("char x = 10; x += -5; return x;"));
// int
assertEquals(15, exec("int x = 5; x += 10; return x;"));
assertEquals(-5, exec("int x = 5; x += -10; return x;"));
// long
assertEquals(15L, exec("long x = 5; x += 10; return x;"));
assertEquals(-5L, exec("long x = 5; x += -10; return x;"));
// float
assertEquals(15F, exec("float x = 5f; x += 10; return x;"));
assertEquals(-5F, exec("float x = 5f; x += -10; return x;"));
// double
assertEquals(15D, exec("double x = 5.0; x += 10; return x;"));
assertEquals(-5D, exec("double x = 5.0; x += -10; return x;"));
}
public void testSubtraction() {
// byte
assertEquals((byte) 15, exec("byte x = 5; x -= -10; return x;"));
assertEquals((byte) -5, exec("byte x = 5; x -= 10; return x;"));
// short
assertEquals((short) 15, exec("short x = 5; x -= -10; return x;"));
assertEquals((short) -5, exec("short x = 5; x -= 10; return x;"));
// char
assertEquals((char) 15, exec("char x = 5; x -= -10; return x;"));
assertEquals((char) 5, exec("char x = 10; x -= 5; return x;"));
// int
assertEquals(15, exec("int x = 5; x -= -10; return x;"));
assertEquals(-5, exec("int x = 5; x -= 10; return x;"));
// long
assertEquals(15L, exec("long x = 5; x -= -10; return x;"));
assertEquals(-5L, exec("long x = 5; x -= 10; return x;"));
// float
assertEquals(15F, exec("float x = 5f; x -= -10; return x;"));
assertEquals(-5F, exec("float x = 5f; x -= 10; return x;"));
// double
assertEquals(15D, exec("double x = 5.0; x -= -10; return x;"));
assertEquals(-5D, exec("double x = 5.0; x -= 10; return x;"));
}
public void testMultiplication() {
// byte
assertEquals((byte) 15, exec("byte x = 5; x *= 3; return x;"));
assertEquals((byte) -5, exec("byte x = 5; x *= -1; return x;"));
// short
assertEquals((short) 15, exec("short x = 5; x *= 3; return x;"));
assertEquals((short) -5, exec("short x = 5; x *= -1; return x;"));
// char
assertEquals((char) 15, exec("char x = 5; x *= 3; return x;"));
// int
assertEquals(15, exec("int x = 5; x *= 3; return x;"));
assertEquals(-5, exec("int x = 5; x *= -1; return x;"));
// long
assertEquals(15L, exec("long x = 5; x *= 3; return x;"));
assertEquals(-5L, exec("long x = 5; x *= -1; return x;"));
// float
assertEquals(15F, exec("float x = 5f; x *= 3; return x;"));
assertEquals(-5F, exec("float x = 5f; x *= -1; return x;"));
// double
assertEquals(15D, exec("double x = 5.0; x *= 3; return x;"));
assertEquals(-5D, exec("double x = 5.0; x *= -1; return x;"));
}
public void testDivision() {
// byte
assertEquals((byte) 15, exec("byte x = 45; x /= 3; return x;"));
assertEquals((byte) -5, exec("byte x = 5; x /= -1; return x;"));
// short
assertEquals((short) 15, exec("short x = 45; x /= 3; return x;"));
assertEquals((short) -5, exec("short x = 5; x /= -1; return x;"));
// char
assertEquals((char) 15, exec("char x = 45; x /= 3; return x;"));
// int
assertEquals(15, exec("int x = 45; x /= 3; return x;"));
assertEquals(-5, exec("int x = 5; x /= -1; return x;"));
// long
assertEquals(15L, exec("long x = 45; x /= 3; return x;"));
assertEquals(-5L, exec("long x = 5; x /= -1; return x;"));
// float
assertEquals(15F, exec("float x = 45f; x /= 3; return x;"));
assertEquals(-5F, exec("float x = 5f; x /= -1; return x;"));
// double
assertEquals(15D, exec("double x = 45.0; x /= 3; return x;"));
assertEquals(-5D, exec("double x = 5.0; x /= -1; return x;"));
}
public void testDivisionByZero() {
// byte
try {
exec("byte x = 1; x /= 0; return x;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
// short
try {
exec("short x = 1; x /= 0; return x;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
// char
try {
exec("char x = 1; x /= 0; return x;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
// int
try {
exec("int x = 1; x /= 0; return x;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
// long
try {
exec("long x = 1; x /= 0; return x;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testRemainder() {
// byte
assertEquals((byte) 3, exec("byte x = 15; x %= 4; return x;"));
assertEquals((byte) -3, exec("byte x = (byte) -15; x %= 4; return x;"));
// short
assertEquals((short) 3, exec("short x = 15; x %= 4; return x;"));
assertEquals((short) -3, exec("short x = (short) -15; x %= 4; return x;"));
// char
assertEquals((char) 3, exec("char x = (char) 15; x %= 4; return x;"));
// int
assertEquals(3, exec("int x = 15; x %= 4; return x;"));
assertEquals(-3, exec("int x = -15; x %= 4; return x;"));
// long
assertEquals(3L, exec("long x = 15L; x %= 4; return x;"));
assertEquals(-3L, exec("long x = -15L; x %= 4; return x;"));
// float
assertEquals(3F, exec("float x = 15F; x %= 4; return x;"));
assertEquals(-3F, exec("float x = -15F; x %= 4; return x;"));
// double
assertEquals(3D, exec("double x = 15.0; x %= 4; return x;"));
assertEquals(-3D, exec("double x = -15.0; x %= 4; return x;"));
}
public void testLeftShift() {
// byte
assertEquals((byte) 60, exec("byte x = 15; x <<= 2; return x;"));
assertEquals((byte) -60, exec("byte x = (byte) -15; x <<= 2; return x;"));
// short
assertEquals((short) 60, exec("short x = 15; x <<= 2; return x;"));
assertEquals((short) -60, exec("short x = (short) -15; x <<= 2; return x;"));
// char
assertEquals((char) 60, exec("char x = (char) 15; x <<= 2; return x;"));
// int
assertEquals(60, exec("int x = 15; x <<= 2; return x;"));
assertEquals(-60, exec("int x = -15; x <<= 2; return x;"));
// long
assertEquals(60L, exec("long x = 15L; x <<= 2; return x;"));
assertEquals(-60L, exec("long x = -15L; x <<= 2; return x;"));
}
public void testRightShift() {
// byte
assertEquals((byte) 15, exec("byte x = 60; x >>= 2; return x;"));
assertEquals((byte) -15, exec("byte x = (byte) -60; x >>= 2; return x;"));
// short
assertEquals((short) 15, exec("short x = 60; x >>= 2; return x;"));
assertEquals((short) -15, exec("short x = (short) -60; x >>= 2; return x;"));
// char
assertEquals((char) 15, exec("char x = (char) 60; x >>= 2; return x;"));
// int
assertEquals(15, exec("int x = 60; x >>= 2; return x;"));
assertEquals(-15, exec("int x = -60; x >>= 2; return x;"));
// long
assertEquals(15L, exec("long x = 60L; x >>= 2; return x;"));
assertEquals(-15L, exec("long x = -60L; x >>= 2; return x;"));
}
public void testUnsignedRightShift() {
// byte
assertEquals((byte) 15, exec("byte x = 60; x >>>= 2; return x;"));
assertEquals((byte) -15, exec("byte x = (byte) -60; x >>>= 2; return x;"));
// short
assertEquals((short) 15, exec("short x = 60; x >>>= 2; return x;"));
assertEquals((short) -15, exec("short x = (short) -60; x >>>= 2; return x;"));
// char
assertEquals((char) 15, exec("char x = (char) 60; x >>>= 2; return x;"));
// int
assertEquals(15, exec("int x = 60; x >>>= 2; return x;"));
assertEquals(-60 >>> 2, exec("int x = -60; x >>>= 2; return x;"));
// long
assertEquals(15L, exec("long x = 60L; x >>>= 2; return x;"));
assertEquals(-60L >>> 2, exec("long x = -60L; x >>>= 2; return x;"));
}
public void testAnd() {
// boolean
assertEquals(true, exec("boolean x = true; x &= true; return x;"));
assertEquals(false, exec("boolean x = true; x &= false; return x;"));
assertEquals(false, exec("boolean x = false; x &= true; return x;"));
assertEquals(false, exec("boolean x = false; x &= false; return x;"));
assertEquals(true, exec("Boolean x = true; x &= true; return x;"));
assertEquals(false, exec("Boolean x = true; x &= false; return x;"));
assertEquals(false, exec("Boolean x = false; x &= true; return x;"));
assertEquals(false, exec("Boolean x = false; x &= false; return x;"));
assertEquals(true, exec("boolean[] x = new boolean[1]; x[0] = true; x[0] &= true; return x[0];"));
assertEquals(false, exec("boolean[] x = new boolean[1]; x[0] = true; x[0] &= false; return x[0];"));
assertEquals(false, exec("boolean[] x = new boolean[1]; x[0] = false; x[0] &= true; return x[0];"));
assertEquals(false, exec("boolean[] x = new boolean[1]; x[0] = false; x[0] &= false; return x[0];"));
assertEquals(true, exec("Boolean[] x = new Boolean[1]; x[0] = true; x[0] &= true; return x[0];"));
assertEquals(false, exec("Boolean[] x = new Boolean[1]; x[0] = true; x[0] &= false; return x[0];"));
assertEquals(false, exec("Boolean[] x = new Boolean[1]; x[0] = false; x[0] &= true; return x[0];"));
assertEquals(false, exec("Boolean[] x = new Boolean[1]; x[0] = false; x[0] &= false; return x[0];"));
// byte
assertEquals((byte) (13 & 14), exec("byte x = 13; x &= 14; return x;"));
// short
assertEquals((short) (13 & 14), exec("short x = 13; x &= 14; return x;"));
// char
assertEquals((char) (13 & 14), exec("char x = 13; x &= 14; return x;"));
// int
assertEquals(13 & 14, exec("int x = 13; x &= 14; return x;"));
// long
assertEquals((long) (13 & 14), exec("long x = 13L; x &= 14; return x;"));
}
public void testOr() {
// boolean
assertEquals(true, exec("boolean x = true; x |= true; return x;"));
assertEquals(true, exec("boolean x = true; x |= false; return x;"));
assertEquals(true, exec("boolean x = false; x |= true; return x;"));
assertEquals(false, exec("boolean x = false; x |= false; return x;"));
assertEquals(true, exec("Boolean x = true; x |= true; return x;"));
assertEquals(true, exec("Boolean x = true; x |= false; return x;"));
assertEquals(true, exec("Boolean x = false; x |= true; return x;"));
assertEquals(false, exec("Boolean x = false; x |= false; return x;"));
assertEquals(true, exec("boolean[] x = new boolean[1]; x[0] = true; x[0] |= true; return x[0];"));
assertEquals(true, exec("boolean[] x = new boolean[1]; x[0] = true; x[0] |= false; return x[0];"));
assertEquals(true, exec("boolean[] x = new boolean[1]; x[0] = false; x[0] |= true; return x[0];"));
assertEquals(false, exec("boolean[] x = new boolean[1]; x[0] = false; x[0] |= false; return x[0];"));
assertEquals(true, exec("Boolean[] x = new Boolean[1]; x[0] = true; x[0] |= true; return x[0];"));
assertEquals(true, exec("Boolean[] x = new Boolean[1]; x[0] = true; x[0] |= false; return x[0];"));
assertEquals(true, exec("Boolean[] x = new Boolean[1]; x[0] = false; x[0] |= true; return x[0];"));
assertEquals(false, exec("Boolean[] x = new Boolean[1]; x[0] = false; x[0] |= false; return x[0];"));
// byte
assertEquals((byte) (13 | 14), exec("byte x = 13; x |= 14; return x;"));
// short
assertEquals((short) (13 | 14), exec("short x = 13; x |= 14; return x;"));
// char
assertEquals((char) (13 | 14), exec("char x = 13; x |= 14; return x;"));
// int
assertEquals(13 | 14, exec("int x = 13; x |= 14; return x;"));
// long
assertEquals((long) (13 | 14), exec("long x = 13L; x |= 14; return x;"));
}
public void testXor() {
// boolean
assertEquals(false, exec("boolean x = true; x ^= true; return x;"));
assertEquals(true, exec("boolean x = true; x ^= false; return x;"));
assertEquals(true, exec("boolean x = false; x ^= true; return x;"));
assertEquals(false, exec("boolean x = false; x ^= false; return x;"));
assertEquals(false, exec("Boolean x = true; x ^= true; return x;"));
assertEquals(true, exec("Boolean x = true; x ^= false; return x;"));
assertEquals(true, exec("Boolean x = false; x ^= true; return x;"));
assertEquals(false, exec("Boolean x = false; x ^= false; return x;"));
assertEquals(false, exec("boolean[] x = new boolean[1]; x[0] = true; x[0] ^= true; return x[0];"));
assertEquals(true, exec("boolean[] x = new boolean[1]; x[0] = true; x[0] ^= false; return x[0];"));
assertEquals(true, exec("boolean[] x = new boolean[1]; x[0] = false; x[0] ^= true; return x[0];"));
assertEquals(false, exec("boolean[] x = new boolean[1]; x[0] = false; x[0] ^= false; return x[0];"));
assertEquals(false, exec("Boolean[] x = new Boolean[1]; x[0] = true; x[0] ^= true; return x[0];"));
assertEquals(true, exec("Boolean[] x = new Boolean[1]; x[0] = true; x[0] ^= false; return x[0];"));
assertEquals(true, exec("Boolean[] x = new Boolean[1]; x[0] = false; x[0] ^= true; return x[0];"));
assertEquals(false, exec("Boolean[] x = new Boolean[1]; x[0] = false; x[0] ^= false; return x[0];"));
// byte
assertEquals((byte) (13 ^ 14), exec("byte x = 13; x ^= 14; return x;"));
// short
assertEquals((short) (13 ^ 14), exec("short x = 13; x ^= 14; return x;"));
// char
assertEquals((char) (13 ^ 14), exec("char x = 13; x ^= 14; return x;"));
// int
assertEquals(13 ^ 14, exec("int x = 13; x ^= 14; return x;"));
// long
assertEquals((long) (13 ^ 14), exec("long x = 13L; x ^= 14; return x;"));
}
}

View File

@ -0,0 +1,93 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import java.util.ArrayList;
import java.util.HashMap;
public class ConditionalTests extends ScriptTestCase {
public void testBasic() {
assertEquals(2, exec("boolean x = true; return x ? 2 : 3;"));
assertEquals(3, exec("boolean x = false; return x ? 2 : 3;"));
assertEquals(3, exec("boolean x = false, y = true; return x && y ? 2 : 3;"));
assertEquals(2, exec("boolean x = true, y = true; return x && y ? 2 : 3;"));
assertEquals(2, exec("boolean x = true, y = false; return x || y ? 2 : 3;"));
assertEquals(3, exec("boolean x = false, y = false; return x || y ? 2 : 3;"));
}
public void testPrecedence() {
assertEquals(4, exec("boolean x = false, y = true; return x ? (y ? 2 : 3) : 4;"));
assertEquals(2, exec("boolean x = true, y = true; return x ? (y ? 2 : 3) : 4;"));
assertEquals(3, exec("boolean x = true, y = false; return x ? (y ? 2 : 3) : 4;"));
assertEquals(2, exec("boolean x = true, y = true; return x ? y ? 2 : 3 : 4;"));
assertEquals(4, exec("boolean x = false, y = true; return x ? y ? 2 : 3 : 4;"));
assertEquals(3, exec("boolean x = true, y = false; return x ? y ? 2 : 3 : 4;"));
assertEquals(3, exec("boolean x = false, y = true; return x ? 2 : y ? 3 : 4;"));
assertEquals(2, exec("boolean x = true, y = false; return x ? 2 : y ? 3 : 4;"));
assertEquals(4, exec("boolean x = false, y = false; return x ? 2 : y ? 3 : 4;"));
assertEquals(4, exec("boolean x = false, y = false; return (x ? true : y) ? 3 : 4;"));
assertEquals(4, exec("boolean x = true, y = false; return (x ? false : y) ? 3 : 4;"));
assertEquals(3, exec("boolean x = false, y = true; return (x ? false : y) ? 3 : 4;"));
assertEquals(2, exec("boolean x = true, y = false; return (x ? false : y) ? (x ? 3 : 4) : x ? 2 : 1;"));
assertEquals(2, exec("boolean x = true, y = false; return (x ? false : y) ? x ? 3 : 4 : x ? 2 : 1;"));
assertEquals(4, exec("boolean x = false, y = true; return x ? false : y ? x ? 3 : 4 : x ? 2 : 1;"));
}
public void testAssignment() {
assertEquals(4D, exec("boolean x = false; double z = x ? 2 : 4.0F; return z;"));
assertEquals((byte)7, exec("boolean x = false; int y = 2; byte z = x ? (byte)y : 7; return z;"));
assertEquals((byte)7, exec("boolean x = false; int y = 2; byte z = (byte)(x ? y : 7); return z;"));
assertEquals(ArrayList.class, exec("boolean x = false; Object z = x ? new HashMap() : new ArrayList(); return z;").getClass());
}
public void testNullArguments() {
assertEquals(null, exec("boolean b = false, c = true; Object x; Map y; return b && c ? x : y;"));
assertEquals(HashMap.class, exec("boolean b = false, c = true; Object x; Map y = new HashMap(); return b && c ? x : y;").getClass());
}
public void testPromotion() {
assertEquals(false, exec("boolean x = false; boolean y = true; return (x ? 2 : 4.0F) == (y ? 2 : 4.0F);"));
assertEquals(false, exec("boolean x = false; boolean y = true; return (x ? 2 : 4.0F) == (y ? new Long(2) : new Float(4.0F));"));
assertEquals(false, exec("boolean x = false; boolean y = true; return (x ? new HashMap() : new ArrayList()) == (y ? new Long(2) : new Float(4.0F));"));
assertEquals(false, exec("boolean x = false; boolean y = true; return (x ? 2 : 4.0F) == (y ? new HashMap() : new ArrayList());"));
}
public void testIncompatibleAssignment() {
try {
exec("boolean x = false; byte z = x ? 2 : 4.0F; return z;");
fail("expected class cast exception");
} catch (ClassCastException expected) {}
try {
exec("boolean x = false; Map z = x ? 4 : (byte)7; return z;");
fail("expected class cast exception");
} catch (ClassCastException expected) {}
try {
exec("boolean x = false; Map z = x ? new HashMap() : new ArrayList(); return z;");
fail("expected class cast exception");
} catch (ClassCastException expected) {}
try {
exec("boolean x = false; int y = 2; byte z = x ? y : 7; return z;");
fail("expected class cast exception");
} catch (ClassCastException expected) {}
}
}

View File

@ -0,0 +1,914 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
public class DefTests extends ScriptTestCase {
public void testNot() {
assertEquals(~1, exec("def x = (byte)1 return ~x"));
assertEquals(~1, exec("def x = (short)1 return ~x"));
assertEquals(~1, exec("def x = (char)1 return ~x"));
assertEquals(~1, exec("def x = 1 return ~x"));
assertEquals(~1L, exec("def x = 1L return ~x"));
}
public void testNeg() {
assertEquals(-1, exec("def x = (byte)1 return -x"));
assertEquals(-1, exec("def x = (short)1 return -x"));
assertEquals(-1, exec("def x = (char)1 return -x"));
assertEquals(-1, exec("def x = 1 return -x"));
assertEquals(-1L, exec("def x = 1L return -x"));
assertEquals(-1.0F, exec("def x = 1F return -x"));
assertEquals(-1.0, exec("def x = 1.0 return -x"));
}
public void testMul() {
assertEquals(4, exec("def x = (byte)2 def y = (byte)2 return x * y"));
assertEquals(4, exec("def x = (short)2 def y = (byte)2 return x * y"));
assertEquals(4, exec("def x = (char)2 def y = (byte)2 return x * y"));
assertEquals(4, exec("def x = (int)2 def y = (byte)2 return x * y"));
assertEquals(4L, exec("def x = (long)2 def y = (byte)2 return x * y"));
assertEquals(4F, exec("def x = (float)2 def y = (byte)2 return x * y"));
assertEquals(4D, exec("def x = (double)2 def y = (byte)2 return x * y"));
assertEquals(4, exec("def x = (byte)2 def y = (short)2 return x * y"));
assertEquals(4, exec("def x = (short)2 def y = (short)2 return x * y"));
assertEquals(4, exec("def x = (char)2 def y = (short)2 return x * y"));
assertEquals(4, exec("def x = (int)2 def y = (short)2 return x * y"));
assertEquals(4L, exec("def x = (long)2 def y = (short)2 return x * y"));
assertEquals(4F, exec("def x = (float)2 def y = (short)2 return x * y"));
assertEquals(4D, exec("def x = (double)2 def y = (short)2 return x * y"));
assertEquals(4, exec("def x = (byte)2 def y = (char)2 return x * y"));
assertEquals(4, exec("def x = (short)2 def y = (char)2 return x * y"));
assertEquals(4, exec("def x = (char)2 def y = (char)2 return x * y"));
assertEquals(4, exec("def x = (int)2 def y = (char)2 return x * y"));
assertEquals(4L, exec("def x = (long)2 def y = (char)2 return x * y"));
assertEquals(4F, exec("def x = (float)2 def y = (char)2 return x * y"));
assertEquals(4D, exec("def x = (double)2 def y = (char)2 return x * y"));
assertEquals(4, exec("def x = (byte)2 def y = (int)2 return x * y"));
assertEquals(4, exec("def x = (short)2 def y = (int)2 return x * y"));
assertEquals(4, exec("def x = (char)2 def y = (int)2 return x * y"));
assertEquals(4, exec("def x = (int)2 def y = (int)2 return x * y"));
assertEquals(4L, exec("def x = (long)2 def y = (int)2 return x * y"));
assertEquals(4F, exec("def x = (float)2 def y = (int)2 return x * y"));
assertEquals(4D, exec("def x = (double)2 def y = (int)2 return x * y"));
assertEquals(4L, exec("def x = (byte)2 def y = (long)2 return x * y"));
assertEquals(4L, exec("def x = (short)2 def y = (long)2 return x * y"));
assertEquals(4L, exec("def x = (char)2 def y = (long)2 return x * y"));
assertEquals(4L, exec("def x = (int)2 def y = (long)2 return x * y"));
assertEquals(4L, exec("def x = (long)2 def y = (long)2 return x * y"));
assertEquals(4F, exec("def x = (float)2 def y = (long)2 return x * y"));
assertEquals(4D, exec("def x = (double)2 def y = (long)2 return x * y"));
assertEquals(4F, exec("def x = (byte)2 def y = (float)2 return x * y"));
assertEquals(4F, exec("def x = (short)2 def y = (float)2 return x * y"));
assertEquals(4F, exec("def x = (char)2 def y = (float)2 return x * y"));
assertEquals(4F, exec("def x = (int)2 def y = (float)2 return x * y"));
assertEquals(4F, exec("def x = (long)2 def y = (float)2 return x * y"));
assertEquals(4F, exec("def x = (float)2 def y = (float)2 return x * y"));
assertEquals(4D, exec("def x = (double)2 def y = (float)2 return x * y"));
assertEquals(4D, exec("def x = (byte)2 def y = (double)2 return x * y"));
assertEquals(4D, exec("def x = (short)2 def y = (double)2 return x * y"));
assertEquals(4D, exec("def x = (char)2 def y = (double)2 return x * y"));
assertEquals(4D, exec("def x = (int)2 def y = (double)2 return x * y"));
assertEquals(4D, exec("def x = (long)2 def y = (double)2 return x * y"));
assertEquals(4D, exec("def x = (float)2 def y = (double)2 return x * y"));
assertEquals(4D, exec("def x = (double)2 def y = (double)2 return x * y"));
assertEquals(4, exec("def x = (Byte)2 def y = (byte)2 return x * y"));
assertEquals(4, exec("def x = (Short)2 def y = (short)2 return x * y"));
assertEquals(4, exec("def x = (Character)2 def y = (char)2 return x * y"));
assertEquals(4, exec("def x = (Integer)2 def y = (int)2 return x * y"));
assertEquals(4L, exec("def x = (Long)2 def y = (long)2 return x * y"));
assertEquals(4F, exec("def x = (Float)2 def y = (float)2 return x * y"));
assertEquals(4D, exec("def x = (Double)2 def y = (double)2 return x * y"));
}
public void testDiv() {
assertEquals(1, exec("def x = (byte)2 def y = (byte)2 return x / y"));
assertEquals(1, exec("def x = (short)2 def y = (byte)2 return x / y"));
assertEquals(1, exec("def x = (char)2 def y = (byte)2 return x / y"));
assertEquals(1, exec("def x = (int)2 def y = (byte)2 return x / y"));
assertEquals(1L, exec("def x = (long)2 def y = (byte)2 return x / y"));
assertEquals(1F, exec("def x = (float)2 def y = (byte)2 return x / y"));
assertEquals(1D, exec("def x = (double)2 def y = (byte)2 return x / y"));
assertEquals(1, exec("def x = (byte)2 def y = (short)2 return x / y"));
assertEquals(1, exec("def x = (short)2 def y = (short)2 return x / y"));
assertEquals(1, exec("def x = (char)2 def y = (short)2 return x / y"));
assertEquals(1, exec("def x = (int)2 def y = (short)2 return x / y"));
assertEquals(1L, exec("def x = (long)2 def y = (short)2 return x / y"));
assertEquals(1F, exec("def x = (float)2 def y = (short)2 return x / y"));
assertEquals(1D, exec("def x = (double)2 def y = (short)2 return x / y"));
assertEquals(1, exec("def x = (byte)2 def y = (char)2 return x / y"));
assertEquals(1, exec("def x = (short)2 def y = (char)2 return x / y"));
assertEquals(1, exec("def x = (char)2 def y = (char)2 return x / y"));
assertEquals(1, exec("def x = (int)2 def y = (char)2 return x / y"));
assertEquals(1L, exec("def x = (long)2 def y = (char)2 return x / y"));
assertEquals(1F, exec("def x = (float)2 def y = (char)2 return x / y"));
assertEquals(1D, exec("def x = (double)2 def y = (char)2 return x / y"));
assertEquals(1, exec("def x = (byte)2 def y = (int)2 return x / y"));
assertEquals(1, exec("def x = (short)2 def y = (int)2 return x / y"));
assertEquals(1, exec("def x = (char)2 def y = (int)2 return x / y"));
assertEquals(1, exec("def x = (int)2 def y = (int)2 return x / y"));
assertEquals(1L, exec("def x = (long)2 def y = (int)2 return x / y"));
assertEquals(1F, exec("def x = (float)2 def y = (int)2 return x / y"));
assertEquals(1D, exec("def x = (double)2 def y = (int)2 return x / y"));
assertEquals(1L, exec("def x = (byte)2 def y = (long)2 return x / y"));
assertEquals(1L, exec("def x = (short)2 def y = (long)2 return x / y"));
assertEquals(1L, exec("def x = (char)2 def y = (long)2 return x / y"));
assertEquals(1L, exec("def x = (int)2 def y = (long)2 return x / y"));
assertEquals(1L, exec("def x = (long)2 def y = (long)2 return x / y"));
assertEquals(1F, exec("def x = (float)2 def y = (long)2 return x / y"));
assertEquals(1D, exec("def x = (double)2 def y = (long)2 return x / y"));
assertEquals(1F, exec("def x = (byte)2 def y = (float)2 return x / y"));
assertEquals(1F, exec("def x = (short)2 def y = (float)2 return x / y"));
assertEquals(1F, exec("def x = (char)2 def y = (float)2 return x / y"));
assertEquals(1F, exec("def x = (int)2 def y = (float)2 return x / y"));
assertEquals(1F, exec("def x = (long)2 def y = (float)2 return x / y"));
assertEquals(1F, exec("def x = (float)2 def y = (float)2 return x / y"));
assertEquals(1D, exec("def x = (double)2 def y = (float)2 return x / y"));
assertEquals(1D, exec("def x = (byte)2 def y = (double)2 return x / y"));
assertEquals(1D, exec("def x = (short)2 def y = (double)2 return x / y"));
assertEquals(1D, exec("def x = (char)2 def y = (double)2 return x / y"));
assertEquals(1D, exec("def x = (int)2 def y = (double)2 return x / y"));
assertEquals(1D, exec("def x = (long)2 def y = (double)2 return x / y"));
assertEquals(1D, exec("def x = (float)2 def y = (double)2 return x / y"));
assertEquals(1D, exec("def x = (double)2 def y = (double)2 return x / y"));
assertEquals(1, exec("def x = (Byte)2 def y = (byte)2 return x / y"));
assertEquals(1, exec("def x = (Short)2 def y = (short)2 return x / y"));
assertEquals(1, exec("def x = (Character)2 def y = (char)2 return x / y"));
assertEquals(1, exec("def x = (Integer)2 def y = (int)2 return x / y"));
assertEquals(1L, exec("def x = (Long)2 def y = (long)2 return x / y"));
assertEquals(1F, exec("def x = (Float)2 def y = (float)2 return x / y"));
assertEquals(1D, exec("def x = (Double)2 def y = (double)2 return x / y"));
}
public void testRem() {
assertEquals(0, exec("def x = (byte)2 def y = (byte)2 return x % y"));
assertEquals(0, exec("def x = (short)2 def y = (byte)2 return x % y"));
assertEquals(0, exec("def x = (char)2 def y = (byte)2 return x % y"));
assertEquals(0, exec("def x = (int)2 def y = (byte)2 return x % y"));
assertEquals(0L, exec("def x = (long)2 def y = (byte)2 return x % y"));
assertEquals(0F, exec("def x = (float)2 def y = (byte)2 return x % y"));
assertEquals(0D, exec("def x = (double)2 def y = (byte)2 return x % y"));
assertEquals(0, exec("def x = (byte)2 def y = (short)2 return x % y"));
assertEquals(0, exec("def x = (short)2 def y = (short)2 return x % y"));
assertEquals(0, exec("def x = (char)2 def y = (short)2 return x % y"));
assertEquals(0, exec("def x = (int)2 def y = (short)2 return x % y"));
assertEquals(0L, exec("def x = (long)2 def y = (short)2 return x % y"));
assertEquals(0F, exec("def x = (float)2 def y = (short)2 return x % y"));
assertEquals(0D, exec("def x = (double)2 def y = (short)2 return x % y"));
assertEquals(0, exec("def x = (byte)2 def y = (char)2 return x % y"));
assertEquals(0, exec("def x = (short)2 def y = (char)2 return x % y"));
assertEquals(0, exec("def x = (char)2 def y = (char)2 return x % y"));
assertEquals(0, exec("def x = (int)2 def y = (char)2 return x % y"));
assertEquals(0L, exec("def x = (long)2 def y = (char)2 return x % y"));
assertEquals(0F, exec("def x = (float)2 def y = (char)2 return x % y"));
assertEquals(0D, exec("def x = (double)2 def y = (char)2 return x % y"));
assertEquals(0, exec("def x = (byte)2 def y = (int)2 return x % y"));
assertEquals(0, exec("def x = (short)2 def y = (int)2 return x % y"));
assertEquals(0, exec("def x = (char)2 def y = (int)2 return x % y"));
assertEquals(0, exec("def x = (int)2 def y = (int)2 return x % y"));
assertEquals(0L, exec("def x = (long)2 def y = (int)2 return x % y"));
assertEquals(0F, exec("def x = (float)2 def y = (int)2 return x % y"));
assertEquals(0D, exec("def x = (double)2 def y = (int)2 return x % y"));
assertEquals(0L, exec("def x = (byte)2 def y = (long)2 return x % y"));
assertEquals(0L, exec("def x = (short)2 def y = (long)2 return x % y"));
assertEquals(0L, exec("def x = (char)2 def y = (long)2 return x % y"));
assertEquals(0L, exec("def x = (int)2 def y = (long)2 return x % y"));
assertEquals(0L, exec("def x = (long)2 def y = (long)2 return x % y"));
assertEquals(0F, exec("def x = (float)2 def y = (long)2 return x % y"));
assertEquals(0D, exec("def x = (double)2 def y = (long)2 return x % y"));
assertEquals(0F, exec("def x = (byte)2 def y = (float)2 return x % y"));
assertEquals(0F, exec("def x = (short)2 def y = (float)2 return x % y"));
assertEquals(0F, exec("def x = (char)2 def y = (float)2 return x % y"));
assertEquals(0F, exec("def x = (int)2 def y = (float)2 return x % y"));
assertEquals(0F, exec("def x = (long)2 def y = (float)2 return x % y"));
assertEquals(0F, exec("def x = (float)2 def y = (float)2 return x % y"));
assertEquals(0D, exec("def x = (double)2 def y = (float)2 return x % y"));
assertEquals(0D, exec("def x = (byte)2 def y = (double)2 return x % y"));
assertEquals(0D, exec("def x = (short)2 def y = (double)2 return x % y"));
assertEquals(0D, exec("def x = (char)2 def y = (double)2 return x % y"));
assertEquals(0D, exec("def x = (int)2 def y = (double)2 return x % y"));
assertEquals(0D, exec("def x = (long)2 def y = (double)2 return x % y"));
assertEquals(0D, exec("def x = (float)2 def y = (double)2 return x % y"));
assertEquals(0D, exec("def x = (double)2 def y = (double)2 return x % y"));
assertEquals(0, exec("def x = (Byte)2 def y = (byte)2 return x % y"));
assertEquals(0, exec("def x = (Short)2 def y = (short)2 return x % y"));
assertEquals(0, exec("def x = (Character)2 def y = (char)2 return x % y"));
assertEquals(0, exec("def x = (Integer)2 def y = (int)2 return x % y"));
assertEquals(0L, exec("def x = (Long)2 def y = (long)2 return x % y"));
assertEquals(0F, exec("def x = (Float)2 def y = (float)2 return x % y"));
assertEquals(0D, exec("def x = (Double)2 def y = (double)2 return x % y"));
}
public void testAdd() {
assertEquals(2, exec("def x = (byte)1 def y = (byte)1 return x + y"));
assertEquals(2, exec("def x = (short)1 def y = (byte)1 return x + y"));
assertEquals(2, exec("def x = (char)1 def y = (byte)1 return x + y"));
assertEquals(2, exec("def x = (int)1 def y = (byte)1 return x + y"));
assertEquals(2L, exec("def x = (long)1 def y = (byte)1 return x + y"));
assertEquals(2F, exec("def x = (float)1 def y = (byte)1 return x + y"));
assertEquals(2D, exec("def x = (double)1 def y = (byte)1 return x + y"));
assertEquals(2, exec("def x = (byte)1 def y = (short)1 return x + y"));
assertEquals(2, exec("def x = (short)1 def y = (short)1 return x + y"));
assertEquals(2, exec("def x = (char)1 def y = (short)1 return x + y"));
assertEquals(2, exec("def x = (int)1 def y = (short)1 return x + y"));
assertEquals(2L, exec("def x = (long)1 def y = (short)1 return x + y"));
assertEquals(2F, exec("def x = (float)1 def y = (short)1 return x + y"));
assertEquals(2D, exec("def x = (double)1 def y = (short)1 return x + y"));
assertEquals(2, exec("def x = (byte)1 def y = (char)1 return x + y"));
assertEquals(2, exec("def x = (short)1 def y = (char)1 return x + y"));
assertEquals(2, exec("def x = (char)1 def y = (char)1 return x + y"));
assertEquals(2, exec("def x = (int)1 def y = (char)1 return x + y"));
assertEquals(2L, exec("def x = (long)1 def y = (char)1 return x + y"));
assertEquals(2F, exec("def x = (float)1 def y = (char)1 return x + y"));
assertEquals(2D, exec("def x = (double)1 def y = (char)1 return x + y"));
assertEquals(2, exec("def x = (byte)1 def y = (int)1 return x + y"));
assertEquals(2, exec("def x = (short)1 def y = (int)1 return x + y"));
assertEquals(2, exec("def x = (char)1 def y = (int)1 return x + y"));
assertEquals(2, exec("def x = (int)1 def y = (int)1 return x + y"));
assertEquals(2L, exec("def x = (long)1 def y = (int)1 return x + y"));
assertEquals(2F, exec("def x = (float)1 def y = (int)1 return x + y"));
assertEquals(2D, exec("def x = (double)1 def y = (int)1 return x + y"));
assertEquals(2L, exec("def x = (byte)1 def y = (long)1 return x + y"));
assertEquals(2L, exec("def x = (short)1 def y = (long)1 return x + y"));
assertEquals(2L, exec("def x = (char)1 def y = (long)1 return x + y"));
assertEquals(2L, exec("def x = (int)1 def y = (long)1 return x + y"));
assertEquals(2L, exec("def x = (long)1 def y = (long)1 return x + y"));
assertEquals(2F, exec("def x = (float)1 def y = (long)1 return x + y"));
assertEquals(2D, exec("def x = (double)1 def y = (long)1 return x + y"));
assertEquals(2F, exec("def x = (byte)1 def y = (float)1 return x + y"));
assertEquals(2F, exec("def x = (short)1 def y = (float)1 return x + y"));
assertEquals(2F, exec("def x = (char)1 def y = (float)1 return x + y"));
assertEquals(2F, exec("def x = (int)1 def y = (float)1 return x + y"));
assertEquals(2F, exec("def x = (long)1 def y = (float)1 return x + y"));
assertEquals(2F, exec("def x = (float)1 def y = (float)1 return x + y"));
assertEquals(2D, exec("def x = (double)1 def y = (float)1 return x + y"));
assertEquals(2D, exec("def x = (byte)1 def y = (double)1 return x + y"));
assertEquals(2D, exec("def x = (short)1 def y = (double)1 return x + y"));
assertEquals(2D, exec("def x = (char)1 def y = (double)1 return x + y"));
assertEquals(2D, exec("def x = (int)1 def y = (double)1 return x + y"));
assertEquals(2D, exec("def x = (long)1 def y = (double)1 return x + y"));
assertEquals(2D, exec("def x = (float)1 def y = (double)1 return x + y"));
assertEquals(2D, exec("def x = (double)1 def y = (double)1 return x + y"));
assertEquals(2, exec("def x = (Byte)1 def y = (byte)1 return x + y"));
assertEquals(2, exec("def x = (Short)1 def y = (short)1 return x + y"));
assertEquals(2, exec("def x = (Character)1 def y = (char)1 return x + y"));
assertEquals(2, exec("def x = (Integer)1 def y = (int)1 return x + y"));
assertEquals(2L, exec("def x = (Long)1 def y = (long)1 return x + y"));
assertEquals(2F, exec("def x = (Float)1 def y = (float)1 return x + y"));
assertEquals(2D, exec("def x = (Double)1 def y = (double)1 return x + y"));
}
public void testSub() {
assertEquals(0, exec("def x = (byte)1 def y = (byte)1 return x - y"));
assertEquals(0, exec("def x = (short)1 def y = (byte)1 return x - y"));
assertEquals(0, exec("def x = (char)1 def y = (byte)1 return x - y"));
assertEquals(0, exec("def x = (int)1 def y = (byte)1 return x - y"));
assertEquals(0L, exec("def x = (long)1 def y = (byte)1 return x - y"));
assertEquals(0F, exec("def x = (float)1 def y = (byte)1 return x - y"));
assertEquals(0D, exec("def x = (double)1 def y = (byte)1 return x - y"));
assertEquals(0, exec("def x = (byte)1 def y = (short)1 return x - y"));
assertEquals(0, exec("def x = (short)1 def y = (short)1 return x - y"));
assertEquals(0, exec("def x = (char)1 def y = (short)1 return x - y"));
assertEquals(0, exec("def x = (int)1 def y = (short)1 return x - y"));
assertEquals(0L, exec("def x = (long)1 def y = (short)1 return x - y"));
assertEquals(0F, exec("def x = (float)1 def y = (short)1 return x - y"));
assertEquals(0D, exec("def x = (double)1 def y = (short)1 return x - y"));
assertEquals(0, exec("def x = (byte)1 def y = (char)1 return x - y"));
assertEquals(0, exec("def x = (short)1 def y = (char)1 return x - y"));
assertEquals(0, exec("def x = (char)1 def y = (char)1 return x - y"));
assertEquals(0, exec("def x = (int)1 def y = (char)1 return x - y"));
assertEquals(0L, exec("def x = (long)1 def y = (char)1 return x - y"));
assertEquals(0F, exec("def x = (float)1 def y = (char)1 return x - y"));
assertEquals(0D, exec("def x = (double)1 def y = (char)1 return x - y"));
assertEquals(0, exec("def x = (byte)1 def y = (int)1 return x - y"));
assertEquals(0, exec("def x = (short)1 def y = (int)1 return x - y"));
assertEquals(0, exec("def x = (char)1 def y = (int)1 return x - y"));
assertEquals(0, exec("def x = (int)1 def y = (int)1 return x - y"));
assertEquals(0L, exec("def x = (long)1 def y = (int)1 return x - y"));
assertEquals(0F, exec("def x = (float)1 def y = (int)1 return x - y"));
assertEquals(0D, exec("def x = (double)1 def y = (int)1 return x - y"));
assertEquals(0L, exec("def x = (byte)1 def y = (long)1 return x - y"));
assertEquals(0L, exec("def x = (short)1 def y = (long)1 return x - y"));
assertEquals(0L, exec("def x = (char)1 def y = (long)1 return x - y"));
assertEquals(0L, exec("def x = (int)1 def y = (long)1 return x - y"));
assertEquals(0L, exec("def x = (long)1 def y = (long)1 return x - y"));
assertEquals(0F, exec("def x = (float)1 def y = (long)1 return x - y"));
assertEquals(0D, exec("def x = (double)1 def y = (long)1 return x - y"));
assertEquals(0F, exec("def x = (byte)1 def y = (float)1 return x - y"));
assertEquals(0F, exec("def x = (short)1 def y = (float)1 return x - y"));
assertEquals(0F, exec("def x = (char)1 def y = (float)1 return x - y"));
assertEquals(0F, exec("def x = (int)1 def y = (float)1 return x - y"));
assertEquals(0F, exec("def x = (long)1 def y = (float)1 return x - y"));
assertEquals(0F, exec("def x = (float)1 def y = (float)1 return x - y"));
assertEquals(0D, exec("def x = (double)1 def y = (float)1 return x - y"));
assertEquals(0D, exec("def x = (byte)1 def y = (double)1 return x - y"));
assertEquals(0D, exec("def x = (short)1 def y = (double)1 return x - y"));
assertEquals(0D, exec("def x = (char)1 def y = (double)1 return x - y"));
assertEquals(0D, exec("def x = (int)1 def y = (double)1 return x - y"));
assertEquals(0D, exec("def x = (long)1 def y = (double)1 return x - y"));
assertEquals(0D, exec("def x = (float)1 def y = (double)1 return x - y"));
assertEquals(0D, exec("def x = (double)1 def y = (double)1 return x - y"));
assertEquals(0, exec("def x = (Byte)1 def y = (byte)1 return x - y"));
assertEquals(0, exec("def x = (Short)1 def y = (short)1 return x - y"));
assertEquals(0, exec("def x = (Character)1 def y = (char)1 return x - y"));
assertEquals(0, exec("def x = (Integer)1 def y = (int)1 return x - y"));
assertEquals(0L, exec("def x = (Long)1 def y = (long)1 return x - y"));
assertEquals(0F, exec("def x = (Float)1 def y = (float)1 return x - y"));
assertEquals(0D, exec("def x = (Double)1 def y = (double)1 return x - y"));
}
public void testLsh() {
assertEquals(2, exec("def x = (byte)1 def y = (byte)1 return x << y"));
assertEquals(2, exec("def x = (short)1 def y = (byte)1 return x << y"));
assertEquals(2, exec("def x = (char)1 def y = (byte)1 return x << y"));
assertEquals(2, exec("def x = (int)1 def y = (byte)1 return x << y"));
assertEquals(2L, exec("def x = (long)1 def y = (byte)1 return x << y"));
assertEquals(2L, exec("def x = (float)1 def y = (byte)1 return x << y"));
assertEquals(2L, exec("def x = (double)1 def y = (byte)1 return x << y"));
assertEquals(2, exec("def x = (byte)1 def y = (short)1 return x << y"));
assertEquals(2, exec("def x = (short)1 def y = (short)1 return x << y"));
assertEquals(2, exec("def x = (char)1 def y = (short)1 return x << y"));
assertEquals(2, exec("def x = (int)1 def y = (short)1 return x << y"));
assertEquals(2L, exec("def x = (long)1 def y = (short)1 return x << y"));
assertEquals(2L, exec("def x = (float)1 def y = (short)1 return x << y"));
assertEquals(2L, exec("def x = (double)1 def y = (short)1 return x << y"));
assertEquals(2, exec("def x = (byte)1 def y = (char)1 return x << y"));
assertEquals(2, exec("def x = (short)1 def y = (char)1 return x << y"));
assertEquals(2, exec("def x = (char)1 def y = (char)1 return x << y"));
assertEquals(2, exec("def x = (int)1 def y = (char)1 return x << y"));
assertEquals(2L, exec("def x = (long)1 def y = (char)1 return x << y"));
assertEquals(2L, exec("def x = (float)1 def y = (char)1 return x << y"));
assertEquals(2L, exec("def x = (double)1 def y = (char)1 return x << y"));
assertEquals(2, exec("def x = (byte)1 def y = (int)1 return x << y"));
assertEquals(2, exec("def x = (short)1 def y = (int)1 return x << y"));
assertEquals(2, exec("def x = (char)1 def y = (int)1 return x << y"));
assertEquals(2, exec("def x = (int)1 def y = (int)1 return x << y"));
assertEquals(2L, exec("def x = (long)1 def y = (int)1 return x << y"));
assertEquals(2L, exec("def x = (float)1 def y = (int)1 return x << y"));
assertEquals(2L, exec("def x = (double)1 def y = (int)1 return x << y"));
assertEquals(2L, exec("def x = (byte)1 def y = (long)1 return x << y"));
assertEquals(2L, exec("def x = (short)1 def y = (long)1 return x << y"));
assertEquals(2L, exec("def x = (char)1 def y = (long)1 return x << y"));
assertEquals(2L, exec("def x = (int)1 def y = (long)1 return x << y"));
assertEquals(2L, exec("def x = (long)1 def y = (long)1 return x << y"));
assertEquals(2L, exec("def x = (float)1 def y = (long)1 return x << y"));
assertEquals(2L, exec("def x = (double)1 def y = (long)1 return x << y"));
assertEquals(2L, exec("def x = (byte)1 def y = (float)1 return x << y"));
assertEquals(2L, exec("def x = (short)1 def y = (float)1 return x << y"));
assertEquals(2L, exec("def x = (char)1 def y = (float)1 return x << y"));
assertEquals(2L, exec("def x = (int)1 def y = (float)1 return x << y"));
assertEquals(2L, exec("def x = (long)1 def y = (float)1 return x << y"));
assertEquals(2L, exec("def x = (float)1 def y = (float)1 return x << y"));
assertEquals(2L, exec("def x = (double)1 def y = (float)1 return x << y"));
assertEquals(2L, exec("def x = (byte)1 def y = (double)1 return x << y"));
assertEquals(2L, exec("def x = (short)1 def y = (double)1 return x << y"));
assertEquals(2L, exec("def x = (char)1 def y = (double)1 return x << y"));
assertEquals(2L, exec("def x = (int)1 def y = (double)1 return x << y"));
assertEquals(2L, exec("def x = (long)1 def y = (double)1 return x << y"));
assertEquals(2L, exec("def x = (float)1 def y = (double)1 return x << y"));
assertEquals(2L, exec("def x = (double)1 def y = (double)1 return x << y"));
assertEquals(2, exec("def x = (Byte)1 def y = (byte)1 return x << y"));
assertEquals(2, exec("def x = (Short)1 def y = (short)1 return x << y"));
assertEquals(2, exec("def x = (Character)1 def y = (char)1 return x << y"));
assertEquals(2, exec("def x = (Integer)1 def y = (int)1 return x << y"));
assertEquals(2L, exec("def x = (Long)1 def y = (long)1 return x << y"));
assertEquals(2L, exec("def x = (Float)1 def y = (float)1 return x << y"));
assertEquals(2L, exec("def x = (Double)1 def y = (double)1 return x << y"));
}
public void testRsh() {
assertEquals(2, exec("def x = (byte)4 def y = (byte)1 return x >> y"));
assertEquals(2, exec("def x = (short)4 def y = (byte)1 return x >> y"));
assertEquals(2, exec("def x = (char)4 def y = (byte)1 return x >> y"));
assertEquals(2, exec("def x = (int)4 def y = (byte)1 return x >> y"));
assertEquals(2L, exec("def x = (long)4 def y = (byte)1 return x >> y"));
assertEquals(2L, exec("def x = (float)4 def y = (byte)1 return x >> y"));
assertEquals(2L, exec("def x = (double)4 def y = (byte)1 return x >> y"));
assertEquals(2, exec("def x = (byte)4 def y = (short)1 return x >> y"));
assertEquals(2, exec("def x = (short)4 def y = (short)1 return x >> y"));
assertEquals(2, exec("def x = (char)4 def y = (short)1 return x >> y"));
assertEquals(2, exec("def x = (int)4 def y = (short)1 return x >> y"));
assertEquals(2L, exec("def x = (long)4 def y = (short)1 return x >> y"));
assertEquals(2L, exec("def x = (float)4 def y = (short)1 return x >> y"));
assertEquals(2L, exec("def x = (double)4 def y = (short)1 return x >> y"));
assertEquals(2, exec("def x = (byte)4 def y = (char)1 return x >> y"));
assertEquals(2, exec("def x = (short)4 def y = (char)1 return x >> y"));
assertEquals(2, exec("def x = (char)4 def y = (char)1 return x >> y"));
assertEquals(2, exec("def x = (int)4 def y = (char)1 return x >> y"));
assertEquals(2L, exec("def x = (long)4 def y = (char)1 return x >> y"));
assertEquals(2L, exec("def x = (float)4 def y = (char)1 return x >> y"));
assertEquals(2L, exec("def x = (double)4 def y = (char)1 return x >> y"));
assertEquals(2, exec("def x = (byte)4 def y = (int)1 return x >> y"));
assertEquals(2, exec("def x = (short)4 def y = (int)1 return x >> y"));
assertEquals(2, exec("def x = (char)4 def y = (int)1 return x >> y"));
assertEquals(2, exec("def x = (int)4 def y = (int)1 return x >> y"));
assertEquals(2L, exec("def x = (long)4 def y = (int)1 return x >> y"));
assertEquals(2L, exec("def x = (float)4 def y = (int)1 return x >> y"));
assertEquals(2L, exec("def x = (double)4 def y = (int)1 return x >> y"));
assertEquals(2L, exec("def x = (byte)4 def y = (long)1 return x >> y"));
assertEquals(2L, exec("def x = (short)4 def y = (long)1 return x >> y"));
assertEquals(2L, exec("def x = (char)4 def y = (long)1 return x >> y"));
assertEquals(2L, exec("def x = (int)4 def y = (long)1 return x >> y"));
assertEquals(2L, exec("def x = (long)4 def y = (long)1 return x >> y"));
assertEquals(2L, exec("def x = (float)4 def y = (long)1 return x >> y"));
assertEquals(2L, exec("def x = (double)4 def y = (long)1 return x >> y"));
assertEquals(2L, exec("def x = (byte)4 def y = (float)1 return x >> y"));
assertEquals(2L, exec("def x = (short)4 def y = (float)1 return x >> y"));
assertEquals(2L, exec("def x = (char)4 def y = (float)1 return x >> y"));
assertEquals(2L, exec("def x = (int)4 def y = (float)1 return x >> y"));
assertEquals(2L, exec("def x = (long)4 def y = (float)1 return x >> y"));
assertEquals(2L, exec("def x = (float)4 def y = (float)1 return x >> y"));
assertEquals(2L, exec("def x = (double)4 def y = (float)1 return x >> y"));
assertEquals(2L, exec("def x = (byte)4 def y = (double)1 return x >> y"));
assertEquals(2L, exec("def x = (short)4 def y = (double)1 return x >> y"));
assertEquals(2L, exec("def x = (char)4 def y = (double)1 return x >> y"));
assertEquals(2L, exec("def x = (int)4 def y = (double)1 return x >> y"));
assertEquals(2L, exec("def x = (long)4 def y = (double)1 return x >> y"));
assertEquals(2L, exec("def x = (float)4 def y = (double)1 return x >> y"));
assertEquals(2L, exec("def x = (double)4 def y = (double)1 return x >> y"));
assertEquals(2, exec("def x = (Byte)4 def y = (byte)1 return x >> y"));
assertEquals(2, exec("def x = (Short)4 def y = (short)1 return x >> y"));
assertEquals(2, exec("def x = (Character)4 def y = (char)1 return x >> y"));
assertEquals(2, exec("def x = (Integer)4 def y = (int)1 return x >> y"));
assertEquals(2L, exec("def x = (Long)4 def y = (long)1 return x >> y"));
assertEquals(2L, exec("def x = (Float)4 def y = (float)1 return x >> y"));
assertEquals(2L, exec("def x = (Double)4 def y = (double)1 return x >> y"));
}
public void testUsh() {
assertEquals(2, exec("def x = (byte)4 def y = (byte)1 return x >>> y"));
assertEquals(2, exec("def x = (short)4 def y = (byte)1 return x >>> y"));
assertEquals(2, exec("def x = (char)4 def y = (byte)1 return x >>> y"));
assertEquals(2, exec("def x = (int)4 def y = (byte)1 return x >>> y"));
assertEquals(2L, exec("def x = (long)4 def y = (byte)1 return x >>> y"));
assertEquals(2L, exec("def x = (float)4 def y = (byte)1 return x >>> y"));
assertEquals(2L, exec("def x = (double)4 def y = (byte)1 return x >>> y"));
assertEquals(2, exec("def x = (byte)4 def y = (short)1 return x >>> y"));
assertEquals(2, exec("def x = (short)4 def y = (short)1 return x >>> y"));
assertEquals(2, exec("def x = (char)4 def y = (short)1 return x >>> y"));
assertEquals(2, exec("def x = (int)4 def y = (short)1 return x >>> y"));
assertEquals(2L, exec("def x = (long)4 def y = (short)1 return x >>> y"));
assertEquals(2L, exec("def x = (float)4 def y = (short)1 return x >>> y"));
assertEquals(2L, exec("def x = (double)4 def y = (short)1 return x >>> y"));
assertEquals(2, exec("def x = (byte)4 def y = (char)1 return x >>> y"));
assertEquals(2, exec("def x = (short)4 def y = (char)1 return x >>> y"));
assertEquals(2, exec("def x = (char)4 def y = (char)1 return x >>> y"));
assertEquals(2, exec("def x = (int)4 def y = (char)1 return x >>> y"));
assertEquals(2L, exec("def x = (long)4 def y = (char)1 return x >>> y"));
assertEquals(2L, exec("def x = (float)4 def y = (char)1 return x >>> y"));
assertEquals(2L, exec("def x = (double)4 def y = (char)1 return x >>> y"));
assertEquals(2, exec("def x = (byte)4 def y = (int)1 return x >>> y"));
assertEquals(2, exec("def x = (short)4 def y = (int)1 return x >>> y"));
assertEquals(2, exec("def x = (char)4 def y = (int)1 return x >>> y"));
assertEquals(2, exec("def x = (int)4 def y = (int)1 return x >>> y"));
assertEquals(2L, exec("def x = (long)4 def y = (int)1 return x >>> y"));
assertEquals(2L, exec("def x = (float)4 def y = (int)1 return x >>> y"));
assertEquals(2L, exec("def x = (double)4 def y = (int)1 return x >>> y"));
assertEquals(2L, exec("def x = (byte)4 def y = (long)1 return x >>> y"));
assertEquals(2L, exec("def x = (short)4 def y = (long)1 return x >>> y"));
assertEquals(2L, exec("def x = (char)4 def y = (long)1 return x >>> y"));
assertEquals(2L, exec("def x = (int)4 def y = (long)1 return x >>> y"));
assertEquals(2L, exec("def x = (long)4 def y = (long)1 return x >>> y"));
assertEquals(2L, exec("def x = (float)4 def y = (long)1 return x >>> y"));
assertEquals(2L, exec("def x = (double)4 def y = (long)1 return x >>> y"));
assertEquals(2L, exec("def x = (byte)4 def y = (float)1 return x >>> y"));
assertEquals(2L, exec("def x = (short)4 def y = (float)1 return x >>> y"));
assertEquals(2L, exec("def x = (char)4 def y = (float)1 return x >>> y"));
assertEquals(2L, exec("def x = (int)4 def y = (float)1 return x >>> y"));
assertEquals(2L, exec("def x = (long)4 def y = (float)1 return x >>> y"));
assertEquals(2L, exec("def x = (float)4 def y = (float)1 return x >>> y"));
assertEquals(2L, exec("def x = (double)4 def y = (float)1 return x >>> y"));
assertEquals(2L, exec("def x = (byte)4 def y = (double)1 return x >>> y"));
assertEquals(2L, exec("def x = (short)4 def y = (double)1 return x >>> y"));
assertEquals(2L, exec("def x = (char)4 def y = (double)1 return x >>> y"));
assertEquals(2L, exec("def x = (int)4 def y = (double)1 return x >>> y"));
assertEquals(2L, exec("def x = (long)4 def y = (double)1 return x >>> y"));
assertEquals(2L, exec("def x = (float)4 def y = (double)1 return x >>> y"));
assertEquals(2L, exec("def x = (double)4 def y = (double)1 return x >>> y"));
assertEquals(2, exec("def x = (Byte)4 def y = (byte)1 return x >>> y"));
assertEquals(2, exec("def x = (Short)4 def y = (short)1 return x >>> y"));
assertEquals(2, exec("def x = (Character)4 def y = (char)1 return x >>> y"));
assertEquals(2, exec("def x = (Integer)4 def y = (int)1 return x >>> y"));
assertEquals(2L, exec("def x = (Long)4 def y = (long)1 return x >>> y"));
assertEquals(2L, exec("def x = (Float)4 def y = (float)1 return x >>> y"));
assertEquals(2L, exec("def x = (Double)4 def y = (double)1 return x >>> y"));
}
public void testAnd() {
assertEquals(0, exec("def x = (byte)4 def y = (byte)1 return x & y"));
assertEquals(0, exec("def x = (short)4 def y = (byte)1 return x & y"));
assertEquals(0, exec("def x = (char)4 def y = (byte)1 return x & y"));
assertEquals(0, exec("def x = (int)4 def y = (byte)1 return x & y"));
assertEquals(0L, exec("def x = (long)4 def y = (byte)1 return x & y"));
assertEquals(0L, exec("def x = (float)4 def y = (byte)1 return x & y"));
assertEquals(0L, exec("def x = (double)4 def y = (byte)1 return x & y"));
assertEquals(0, exec("def x = (byte)4 def y = (short)1 return x & y"));
assertEquals(0, exec("def x = (short)4 def y = (short)1 return x & y"));
assertEquals(0, exec("def x = (char)4 def y = (short)1 return x & y"));
assertEquals(0, exec("def x = (int)4 def y = (short)1 return x & y"));
assertEquals(0L, exec("def x = (long)4 def y = (short)1 return x & y"));
assertEquals(0L, exec("def x = (float)4 def y = (short)1 return x & y"));
assertEquals(0L, exec("def x = (double)4 def y = (short)1 return x & y"));
assertEquals(0, exec("def x = (byte)4 def y = (char)1 return x & y"));
assertEquals(0, exec("def x = (short)4 def y = (char)1 return x & y"));
assertEquals(0, exec("def x = (char)4 def y = (char)1 return x & y"));
assertEquals(0, exec("def x = (int)4 def y = (char)1 return x & y"));
assertEquals(0L, exec("def x = (long)4 def y = (char)1 return x & y"));
assertEquals(0L, exec("def x = (float)4 def y = (char)1 return x & y"));
assertEquals(0L, exec("def x = (double)4 def y = (char)1 return x & y"));
assertEquals(0, exec("def x = (byte)4 def y = (int)1 return x & y"));
assertEquals(0, exec("def x = (short)4 def y = (int)1 return x & y"));
assertEquals(0, exec("def x = (char)4 def y = (int)1 return x & y"));
assertEquals(0, exec("def x = (int)4 def y = (int)1 return x & y"));
assertEquals(0L, exec("def x = (long)4 def y = (int)1 return x & y"));
assertEquals(0L, exec("def x = (float)4 def y = (int)1 return x & y"));
assertEquals(0L, exec("def x = (double)4 def y = (int)1 return x & y"));
assertEquals(0L, exec("def x = (byte)4 def y = (long)1 return x & y"));
assertEquals(0L, exec("def x = (short)4 def y = (long)1 return x & y"));
assertEquals(0L, exec("def x = (char)4 def y = (long)1 return x & y"));
assertEquals(0L, exec("def x = (int)4 def y = (long)1 return x & y"));
assertEquals(0L, exec("def x = (long)4 def y = (long)1 return x & y"));
assertEquals(0L, exec("def x = (float)4 def y = (long)1 return x & y"));
assertEquals(0L, exec("def x = (double)4 def y = (long)1 return x & y"));
assertEquals(0L, exec("def x = (byte)4 def y = (float)1 return x & y"));
assertEquals(0L, exec("def x = (short)4 def y = (float)1 return x & y"));
assertEquals(0L, exec("def x = (char)4 def y = (float)1 return x & y"));
assertEquals(0L, exec("def x = (int)4 def y = (float)1 return x & y"));
assertEquals(0L, exec("def x = (long)4 def y = (float)1 return x & y"));
assertEquals(0L, exec("def x = (float)4 def y = (float)1 return x & y"));
assertEquals(0L, exec("def x = (double)4 def y = (float)1 return x & y"));
assertEquals(0L, exec("def x = (byte)4 def y = (double)1 return x & y"));
assertEquals(0L, exec("def x = (short)4 def y = (double)1 return x & y"));
assertEquals(0L, exec("def x = (char)4 def y = (double)1 return x & y"));
assertEquals(0L, exec("def x = (int)4 def y = (double)1 return x & y"));
assertEquals(0L, exec("def x = (long)4 def y = (double)1 return x & y"));
assertEquals(0L, exec("def x = (float)4 def y = (double)1 return x & y"));
assertEquals(0L, exec("def x = (double)4 def y = (double)1 return x & y"));
assertEquals(0, exec("def x = (Byte)4 def y = (byte)1 return x & y"));
assertEquals(0, exec("def x = (Short)4 def y = (short)1 return x & y"));
assertEquals(0, exec("def x = (Character)4 def y = (char)1 return x & y"));
assertEquals(0, exec("def x = (Integer)4 def y = (int)1 return x & y"));
assertEquals(0L, exec("def x = (Long)4 def y = (long)1 return x & y"));
assertEquals(0L, exec("def x = (Float)4 def y = (float)1 return x & y"));
assertEquals(0L, exec("def x = (Double)4 def y = (double)1 return x & y"));
}
public void testXor() {
assertEquals(5, exec("def x = (byte)4 def y = (byte)1 return x ^ y"));
assertEquals(5, exec("def x = (short)4 def y = (byte)1 return x ^ y"));
assertEquals(5, exec("def x = (char)4 def y = (byte)1 return x ^ y"));
assertEquals(5, exec("def x = (int)4 def y = (byte)1 return x ^ y"));
assertEquals(5L, exec("def x = (long)4 def y = (byte)1 return x ^ y"));
assertEquals(5L, exec("def x = (float)4 def y = (byte)1 return x ^ y"));
assertEquals(5L, exec("def x = (double)4 def y = (byte)1 return x ^ y"));
assertEquals(5, exec("def x = (byte)4 def y = (short)1 return x ^ y"));
assertEquals(5, exec("def x = (short)4 def y = (short)1 return x ^ y"));
assertEquals(5, exec("def x = (char)4 def y = (short)1 return x ^ y"));
assertEquals(5, exec("def x = (int)4 def y = (short)1 return x ^ y"));
assertEquals(5L, exec("def x = (long)4 def y = (short)1 return x ^ y"));
assertEquals(5L, exec("def x = (float)4 def y = (short)1 return x ^ y"));
assertEquals(5L, exec("def x = (double)4 def y = (short)1 return x ^ y"));
assertEquals(5, exec("def x = (byte)4 def y = (char)1 return x ^ y"));
assertEquals(5, exec("def x = (short)4 def y = (char)1 return x ^ y"));
assertEquals(5, exec("def x = (char)4 def y = (char)1 return x ^ y"));
assertEquals(5, exec("def x = (int)4 def y = (char)1 return x ^ y"));
assertEquals(5L, exec("def x = (long)4 def y = (char)1 return x ^ y"));
assertEquals(5L, exec("def x = (float)4 def y = (char)1 return x ^ y"));
assertEquals(5L, exec("def x = (double)4 def y = (char)1 return x ^ y"));
assertEquals(5, exec("def x = (byte)4 def y = (int)1 return x ^ y"));
assertEquals(5, exec("def x = (short)4 def y = (int)1 return x ^ y"));
assertEquals(5, exec("def x = (char)4 def y = (int)1 return x ^ y"));
assertEquals(5, exec("def x = (int)4 def y = (int)1 return x ^ y"));
assertEquals(5L, exec("def x = (long)4 def y = (int)1 return x ^ y"));
assertEquals(5L, exec("def x = (float)4 def y = (int)1 return x ^ y"));
assertEquals(5L, exec("def x = (double)4 def y = (int)1 return x ^ y"));
assertEquals(5L, exec("def x = (byte)4 def y = (long)1 return x ^ y"));
assertEquals(5L, exec("def x = (short)4 def y = (long)1 return x ^ y"));
assertEquals(5L, exec("def x = (char)4 def y = (long)1 return x ^ y"));
assertEquals(5L, exec("def x = (int)4 def y = (long)1 return x ^ y"));
assertEquals(5L, exec("def x = (long)4 def y = (long)1 return x ^ y"));
assertEquals(5L, exec("def x = (float)4 def y = (long)1 return x ^ y"));
assertEquals(5L, exec("def x = (double)4 def y = (long)1 return x ^ y"));
assertEquals(5L, exec("def x = (byte)4 def y = (float)1 return x ^ y"));
assertEquals(5L, exec("def x = (short)4 def y = (float)1 return x ^ y"));
assertEquals(5L, exec("def x = (char)4 def y = (float)1 return x ^ y"));
assertEquals(5L, exec("def x = (int)4 def y = (float)1 return x ^ y"));
assertEquals(5L, exec("def x = (long)4 def y = (float)1 return x ^ y"));
assertEquals(5L, exec("def x = (float)4 def y = (float)1 return x ^ y"));
assertEquals(5L, exec("def x = (double)4 def y = (float)1 return x ^ y"));
assertEquals(5L, exec("def x = (byte)4 def y = (double)1 return x ^ y"));
assertEquals(5L, exec("def x = (short)4 def y = (double)1 return x ^ y"));
assertEquals(5L, exec("def x = (char)4 def y = (double)1 return x ^ y"));
assertEquals(5L, exec("def x = (int)4 def y = (double)1 return x ^ y"));
assertEquals(5L, exec("def x = (long)4 def y = (double)1 return x ^ y"));
assertEquals(5L, exec("def x = (float)4 def y = (double)1 return x ^ y"));
assertEquals(5L, exec("def x = (double)4 def y = (double)1 return x ^ y"));
assertEquals(5, exec("def x = (Byte)4 def y = (byte)1 return x ^ y"));
assertEquals(5, exec("def x = (Short)4 def y = (short)1 return x ^ y"));
assertEquals(5, exec("def x = (Character)4 def y = (char)1 return x ^ y"));
assertEquals(5, exec("def x = (Integer)4 def y = (int)1 return x ^ y"));
assertEquals(5L, exec("def x = (Long)4 def y = (long)1 return x ^ y"));
assertEquals(5L, exec("def x = (Float)4 def y = (float)1 return x ^ y"));
assertEquals(5L, exec("def x = (Double)4 def y = (double)1 return x ^ y"));
}
public void testOr() {
assertEquals(5, exec("def x = (byte)4 def y = (byte)1 return x | y"));
assertEquals(5, exec("def x = (short)4 def y = (byte)1 return x | y"));
assertEquals(5, exec("def x = (char)4 def y = (byte)1 return x | y"));
assertEquals(5, exec("def x = (int)4 def y = (byte)1 return x | y"));
assertEquals(5L, exec("def x = (long)4 def y = (byte)1 return x | y"));
assertEquals(5L, exec("def x = (float)4 def y = (byte)1 return x | y"));
assertEquals(5L, exec("def x = (double)4 def y = (byte)1 return x | y"));
assertEquals(5, exec("def x = (byte)4 def y = (short)1 return x | y"));
assertEquals(5, exec("def x = (short)4 def y = (short)1 return x | y"));
assertEquals(5, exec("def x = (char)4 def y = (short)1 return x | y"));
assertEquals(5, exec("def x = (int)4 def y = (short)1 return x | y"));
assertEquals(5L, exec("def x = (long)4 def y = (short)1 return x | y"));
assertEquals(5L, exec("def x = (float)4 def y = (short)1 return x | y"));
assertEquals(5L, exec("def x = (double)4 def y = (short)1 return x | y"));
assertEquals(5, exec("def x = (byte)4 def y = (char)1 return x | y"));
assertEquals(5, exec("def x = (short)4 def y = (char)1 return x | y"));
assertEquals(5, exec("def x = (char)4 def y = (char)1 return x | y"));
assertEquals(5, exec("def x = (int)4 def y = (char)1 return x | y"));
assertEquals(5L, exec("def x = (long)4 def y = (char)1 return x | y"));
assertEquals(5L, exec("def x = (float)4 def y = (char)1 return x | y"));
assertEquals(5L, exec("def x = (double)4 def y = (char)1 return x | y"));
assertEquals(5, exec("def x = (byte)4 def y = (int)1 return x | y"));
assertEquals(5, exec("def x = (short)4 def y = (int)1 return x | y"));
assertEquals(5, exec("def x = (char)4 def y = (int)1 return x | y"));
assertEquals(5, exec("def x = (int)4 def y = (int)1 return x | y"));
assertEquals(5L, exec("def x = (long)4 def y = (int)1 return x | y"));
assertEquals(5L, exec("def x = (float)4 def y = (int)1 return x | y"));
assertEquals(5L, exec("def x = (double)4 def y = (int)1 return x | y"));
assertEquals(5L, exec("def x = (byte)4 def y = (long)1 return x | y"));
assertEquals(5L, exec("def x = (short)4 def y = (long)1 return x | y"));
assertEquals(5L, exec("def x = (char)4 def y = (long)1 return x | y"));
assertEquals(5L, exec("def x = (int)4 def y = (long)1 return x | y"));
assertEquals(5L, exec("def x = (long)4 def y = (long)1 return x | y"));
assertEquals(5L, exec("def x = (float)4 def y = (long)1 return x | y"));
assertEquals(5L, exec("def x = (double)4 def y = (long)1 return x | y"));
assertEquals(5L, exec("def x = (byte)4 def y = (float)1 return x | y"));
assertEquals(5L, exec("def x = (short)4 def y = (float)1 return x | y"));
assertEquals(5L, exec("def x = (char)4 def y = (float)1 return x | y"));
assertEquals(5L, exec("def x = (int)4 def y = (float)1 return x | y"));
assertEquals(5L, exec("def x = (long)4 def y = (float)1 return x | y"));
assertEquals(5L, exec("def x = (float)4 def y = (float)1 return x | y"));
assertEquals(5L, exec("def x = (double)4 def y = (float)1 return x | y"));
assertEquals(5L, exec("def x = (byte)4 def y = (double)1 return x | y"));
assertEquals(5L, exec("def x = (short)4 def y = (double)1 return x | y"));
assertEquals(5L, exec("def x = (char)4 def y = (double)1 return x | y"));
assertEquals(5L, exec("def x = (int)4 def y = (double)1 return x | y"));
assertEquals(5L, exec("def x = (long)4 def y = (double)1 return x | y"));
assertEquals(5L, exec("def x = (float)4 def y = (double)1 return x | y"));
assertEquals(5L, exec("def x = (double)4 def y = (double)1 return x | y"));
assertEquals(5, exec("def x = (Byte)4 def y = (byte)1 return x | y"));
assertEquals(5, exec("def x = (Short)4 def y = (short)1 return x | y"));
assertEquals(5, exec("def x = (Character)4 def y = (char)1 return x | y"));
assertEquals(5, exec("def x = (Integer)4 def y = (int)1 return x | y"));
assertEquals(5L, exec("def x = (Long)4 def y = (long)1 return x | y"));
assertEquals(5L, exec("def x = (Float)4 def y = (float)1 return x | y"));
assertEquals(5L, exec("def x = (Double)4 def y = (double)1 return x | y"));
}
public void testEq() {
assertEquals(true, exec("def x = (byte)7 def y = (int)7 return x == y"));
assertEquals(true, exec("def x = (short)6 def y = (int)6 return x == y"));
assertEquals(true, exec("def x = (char)5 def y = (int)5 return x == y"));
assertEquals(true, exec("def x = (int)4 def y = (int)4 return x == y"));
assertEquals(false, exec("def x = (long)5 def y = (int)3 return x == y"));
assertEquals(false, exec("def x = (float)6 def y = (int)2 return x == y"));
assertEquals(false, exec("def x = (double)7 def y = (int)1 return x == y"));
assertEquals(true, exec("def x = (byte)7 def y = (double)7 return x == y"));
assertEquals(true, exec("def x = (short)6 def y = (double)6 return x == y"));
assertEquals(true, exec("def x = (char)5 def y = (double)5 return x == y"));
assertEquals(true, exec("def x = (int)4 def y = (double)4 return x == y"));
assertEquals(false, exec("def x = (long)5 def y = (double)3 return x == y"));
assertEquals(false, exec("def x = (float)6 def y = (double)2 return x == y"));
assertEquals(false, exec("def x = (double)7 def y = (double)1 return x == y"));
assertEquals(true, exec("def x = new HashMap() def y = new HashMap() return x == y"));
assertEquals(false, exec("def x = new HashMap() x.put(3, 3) def y = new HashMap() return x == y"));
assertEquals(true, exec("def x = new HashMap() x.put(3, 3) def y = new HashMap() y.put(3, 3) return x == y"));
assertEquals(true, exec("def x = new HashMap() def y = x x.put(3, 3) y.put(3, 3) return x == y"));
}
public void testEqr() {
assertEquals(false, exec("def x = (byte)7 def y = (int)7 return x === y"));
assertEquals(false, exec("def x = (short)6 def y = (int)6 return x === y"));
assertEquals(false, exec("def x = (char)5 def y = (int)5 return x === y"));
assertEquals(true, exec("def x = (int)4 def y = (int)4 return x === y"));
assertEquals(false, exec("def x = (long)5 def y = (int)3 return x === y"));
assertEquals(false, exec("def x = (float)6 def y = (int)2 return x === y"));
assertEquals(false, exec("def x = (double)7 def y = (int)1 return x === y"));
assertEquals(false, exec("def x = new HashMap() def y = new HashMap() return x === y"));
assertEquals(false, exec("def x = new HashMap() x.put(3, 3) def y = new HashMap() return x === y"));
assertEquals(false, exec("def x = new HashMap() x.put(3, 3) def y = new HashMap() y.put(3, 3) return x === y"));
assertEquals(true, exec("def x = new HashMap() def y = x x.put(3, 3) y.put(3, 3) return x === y"));
}
public void testNe() {
assertEquals(false, exec("def x = (byte)7 def y = (int)7 return x != y"));
assertEquals(false, exec("def x = (short)6 def y = (int)6 return x != y"));
assertEquals(false, exec("def x = (char)5 def y = (int)5 return x != y"));
assertEquals(false, exec("def x = (int)4 def y = (int)4 return x != y"));
assertEquals(true, exec("def x = (long)5 def y = (int)3 return x != y"));
assertEquals(true, exec("def x = (float)6 def y = (int)2 return x != y"));
assertEquals(true, exec("def x = (double)7 def y = (int)1 return x != y"));
assertEquals(false, exec("def x = (byte)7 def y = (double)7 return x != y"));
assertEquals(false, exec("def x = (short)6 def y = (double)6 return x != y"));
assertEquals(false, exec("def x = (char)5 def y = (double)5 return x != y"));
assertEquals(false, exec("def x = (int)4 def y = (double)4 return x != y"));
assertEquals(true, exec("def x = (long)5 def y = (double)3 return x != y"));
assertEquals(true, exec("def x = (float)6 def y = (double)2 return x != y"));
assertEquals(true, exec("def x = (double)7 def y = (double)1 return x != y"));
assertEquals(false, exec("def x = new HashMap() def y = new HashMap() return x != y"));
assertEquals(true, exec("def x = new HashMap() x.put(3, 3) def y = new HashMap() return x != y"));
assertEquals(false, exec("def x = new HashMap() x.put(3, 3) def y = new HashMap() y.put(3, 3) return x != y"));
assertEquals(false, exec("def x = new HashMap() def y = x x.put(3, 3) y.put(3, 3) return x != y"));
}
public void testNer() {
assertEquals(true, exec("def x = (byte)7 def y = (int)7 return x !== y"));
assertEquals(true, exec("def x = (short)6 def y = (int)6 return x !== y"));
assertEquals(true, exec("def x = (char)5 def y = (int)5 return x !== y"));
assertEquals(false, exec("def x = (int)4 def y = (int)4 return x !== y"));
assertEquals(true, exec("def x = (long)5 def y = (int)3 return x !== y"));
assertEquals(true, exec("def x = (float)6 def y = (int)2 return x !== y"));
assertEquals(true, exec("def x = (double)7 def y = (int)1 return x !== y"));
assertEquals(true, exec("def x = new HashMap() def y = new HashMap() return x !== y"));
assertEquals(true, exec("def x = new HashMap() x.put(3, 3) def y = new HashMap() return x !== y"));
assertEquals(true, exec("def x = new HashMap() x.put(3, 3) def y = new HashMap() y.put(3, 3) return x !== y"));
assertEquals(false, exec("def x = new HashMap() def y = x x.put(3, 3) y.put(3, 3) return x !== y"));
}
public void testLt() {
assertEquals(true, exec("def x = (byte)1 def y = (int)7 return x < y"));
assertEquals(true, exec("def x = (short)2 def y = (int)6 return x < y"));
assertEquals(true, exec("def x = (char)3 def y = (int)5 return x < y"));
assertEquals(false, exec("def x = (int)4 def y = (int)4 return x < y"));
assertEquals(false, exec("def x = (long)5 def y = (int)3 return x < y"));
assertEquals(false, exec("def x = (float)6 def y = (int)2 return x < y"));
assertEquals(false, exec("def x = (double)7 def y = (int)1 return x < y"));
assertEquals(true, exec("def x = (byte)1 def y = (double)7 return x < y"));
assertEquals(true, exec("def x = (short)2 def y = (double)6 return x < y"));
assertEquals(true, exec("def x = (char)3 def y = (double)5 return x < y"));
assertEquals(false, exec("def x = (int)4 def y = (double)4 return x < y"));
assertEquals(false, exec("def x = (long)5 def y = (double)3 return x < y"));
assertEquals(false, exec("def x = (float)6 def y = (double)2 return x < y"));
assertEquals(false, exec("def x = (double)7 def y = (double)1 return x < y"));
}
public void testLte() {
assertEquals(true, exec("def x = (byte)1 def y = (int)7 return x <= y"));
assertEquals(true, exec("def x = (short)2 def y = (int)6 return x <= y"));
assertEquals(true, exec("def x = (char)3 def y = (int)5 return x <= y"));
assertEquals(true, exec("def x = (int)4 def y = (int)4 return x <= y"));
assertEquals(false, exec("def x = (long)5 def y = (int)3 return x <= y"));
assertEquals(false, exec("def x = (float)6 def y = (int)2 return x <= y"));
assertEquals(false, exec("def x = (double)7 def y = (int)1 return x <= y"));
assertEquals(true, exec("def x = (byte)1 def y = (double)7 return x <= y"));
assertEquals(true, exec("def x = (short)2 def y = (double)6 return x <= y"));
assertEquals(true, exec("def x = (char)3 def y = (double)5 return x <= y"));
assertEquals(true, exec("def x = (int)4 def y = (double)4 return x <= y"));
assertEquals(false, exec("def x = (long)5 def y = (double)3 return x <= y"));
assertEquals(false, exec("def x = (float)6 def y = (double)2 return x <= y"));
assertEquals(false, exec("def x = (double)7 def y = (double)1 return x <= y"));
}
public void testGt() {
assertEquals(false, exec("def x = (byte)1 def y = (int)7 return x > y"));
assertEquals(false, exec("def x = (short)2 def y = (int)6 return x > y"));
assertEquals(false, exec("def x = (char)3 def y = (int)5 return x > y"));
assertEquals(false, exec("def x = (int)4 def y = (int)4 return x > y"));
assertEquals(true, exec("def x = (long)5 def y = (int)3 return x > y"));
assertEquals(true, exec("def x = (float)6 def y = (int)2 return x > y"));
assertEquals(true, exec("def x = (double)7 def y = (int)1 return x > y"));
assertEquals(false, exec("def x = (byte)1 def y = (double)7 return x > y"));
assertEquals(false, exec("def x = (short)2 def y = (double)6 return x > y"));
assertEquals(false, exec("def x = (char)3 def y = (double)5 return x > y"));
assertEquals(false, exec("def x = (int)4 def y = (double)4 return x > y"));
assertEquals(true, exec("def x = (long)5 def y = (double)3 return x > y"));
assertEquals(true, exec("def x = (float)6 def y = (double)2 return x > y"));
assertEquals(true, exec("def x = (double)7 def y = (double)1 return x > y"));
}
public void testGte() {
assertEquals(false, exec("def x = (byte)1 def y = (int)7 return x >= y"));
assertEquals(false, exec("def x = (short)2 def y = (int)6 return x >= y"));
assertEquals(false, exec("def x = (char)3 def y = (int)5 return x >= y"));
assertEquals(true, exec("def x = (int)4 def y = (int)4 return x >= y"));
assertEquals(true, exec("def x = (long)5 def y = (int)3 return x >= y"));
assertEquals(true, exec("def x = (float)6 def y = (int)2 return x >= y"));
assertEquals(true, exec("def x = (double)7 def y = (int)1 return x >= y"));
assertEquals(false, exec("def x = (byte)1 def y = (double)7 return x >= y"));
assertEquals(false, exec("def x = (short)2 def y = (double)6 return x >= y"));
assertEquals(false, exec("def x = (char)3 def y = (double)5 return x >= y"));
assertEquals(true, exec("def x = (int)4 def y = (double)4 return x >= y"));
assertEquals(true, exec("def x = (long)5 def y = (double)3 return x >= y"));
assertEquals(true, exec("def x = (float)6 def y = (double)2 return x >= y"));
assertEquals(true, exec("def x = (double)7 def y = (double)1 return x >= y"));
}
}

View File

@ -0,0 +1,147 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/** Tests for division operator across all types */
//TODO: NaN/Inf/overflow/...
public class DivisionTests extends ScriptTestCase {
// TODO: byte,short,char
public void testInt() throws Exception {
assertEquals(1/1, exec("int x = 1; int y = 1; return x/y;"));
assertEquals(2/3, exec("int x = 2; int y = 3; return x/y;"));
assertEquals(5/10, exec("int x = 5; int y = 10; return x/y;"));
assertEquals(10/1/2, exec("int x = 10; int y = 1; int z = 2; return x/y/z;"));
assertEquals((10/1)/2, exec("int x = 10; int y = 1; int z = 2; return (x/y)/z;"));
assertEquals(10/(4/2), exec("int x = 10; int y = 4; int z = 2; return x/(y/z);"));
assertEquals(10/1, exec("int x = 10; int y = 1; return x/y;"));
assertEquals(0/1, exec("int x = 0; int y = 1; return x/y;"));
}
public void testIntConst() throws Exception {
assertEquals(1/1, exec("return 1/1;"));
assertEquals(2/3, exec("return 2/3;"));
assertEquals(5/10, exec("return 5/10;"));
assertEquals(10/1/2, exec("return 10/1/2;"));
assertEquals((10/1)/2, exec("return (10/1)/2;"));
assertEquals(10/(4/2), exec("return 10/(4/2);"));
assertEquals(10/1, exec("return 10/1;"));
assertEquals(0/1, exec("return 0/1;"));
}
public void testLong() throws Exception {
assertEquals(1L/1L, exec("long x = 1; long y = 1; return x/y;"));
assertEquals(2L/3L, exec("long x = 2; long y = 3; return x/y;"));
assertEquals(5L/10L, exec("long x = 5; long y = 10; return x/y;"));
assertEquals(10L/1L/2L, exec("long x = 10; long y = 1; long z = 2; return x/y/z;"));
assertEquals((10L/1L)/2L, exec("long x = 10; long y = 1; long z = 2; return (x/y)/z;"));
assertEquals(10L/(4L/2L), exec("long x = 10; long y = 4; long z = 2; return x/(y/z);"));
assertEquals(10L/1L, exec("long x = 10; long y = 1; return x/y;"));
assertEquals(0L/1L, exec("long x = 0; long y = 1; return x/y;"));
}
public void testLongConst() throws Exception {
assertEquals(1L/1L, exec("return 1L/1L;"));
assertEquals(2L/3L, exec("return 2L/3L;"));
assertEquals(5L/10L, exec("return 5L/10L;"));
assertEquals(10L/1L/2L, exec("return 10L/1L/2L;"));
assertEquals((10L/1L)/2L, exec("return (10L/1L)/2L;"));
assertEquals(10L/(4L/2L), exec("return 10L/(4L/2L);"));
assertEquals(10L/1L, exec("return 10L/1L;"));
assertEquals(0L/1L, exec("return 0L/1L;"));
}
public void testFloat() throws Exception {
assertEquals(1F/1F, exec("float x = 1; float y = 1; return x/y;"));
assertEquals(2F/3F, exec("float x = 2; float y = 3; return x/y;"));
assertEquals(5F/10F, exec("float x = 5; float y = 10; return x/y;"));
assertEquals(10F/1F/2F, exec("float x = 10; float y = 1; float z = 2; return x/y/z;"));
assertEquals((10F/1F)/2F, exec("float x = 10; float y = 1; float z = 2; return (x/y)/z;"));
assertEquals(10F/(4F/2F), exec("float x = 10; float y = 4; float z = 2; return x/(y/z);"));
assertEquals(10F/1F, exec("float x = 10; float y = 1; return x/y;"));
assertEquals(0F/1F, exec("float x = 0; float y = 1; return x/y;"));
}
public void testFloatConst() throws Exception {
assertEquals(1F/1F, exec("return 1F/1F;"));
assertEquals(2F/3F, exec("return 2F/3F;"));
assertEquals(5F/10F, exec("return 5F/10F;"));
assertEquals(10F/1F/2F, exec("return 10F/1F/2F;"));
assertEquals((10F/1F)/2F, exec("return (10F/1F)/2F;"));
assertEquals(10F/(4F/2F), exec("return 10F/(4F/2F);"));
assertEquals(10F/1F, exec("return 10F/1F;"));
assertEquals(0F/1F, exec("return 0F/1F;"));
}
public void testDouble() throws Exception {
assertEquals(1.0/1.0, exec("double x = 1; double y = 1; return x/y;"));
assertEquals(2.0/3.0, exec("double x = 2; double y = 3; return x/y;"));
assertEquals(5.0/10.0, exec("double x = 5; double y = 10; return x/y;"));
assertEquals(10.0/1.0/2.0, exec("double x = 10; double y = 1; double z = 2; return x/y/z;"));
assertEquals((10.0/1.0)/2.0, exec("double x = 10; double y = 1; double z = 2; return (x/y)/z;"));
assertEquals(10.0/(4.0/2.0), exec("double x = 10; double y = 4; double z = 2; return x/(y/z);"));
assertEquals(10.0/1.0, exec("double x = 10; double y = 1; return x/y;"));
assertEquals(0.0/1.0, exec("double x = 0; double y = 1; return x/y;"));
}
public void testDoubleConst() throws Exception {
assertEquals(1.0/1.0, exec("return 1.0/1.0;"));
assertEquals(2.0/3.0, exec("return 2.0/3.0;"));
assertEquals(5.0/10.0, exec("return 5.0/10.0;"));
assertEquals(10.0/1.0/2.0, exec("return 10.0/1.0/2.0;"));
assertEquals((10.0/1.0)/2.0, exec("return (10.0/1.0)/2.0;"));
assertEquals(10.0/(4.0/2.0), exec("return 10.0/(4.0/2.0);"));
assertEquals(10.0/1.0, exec("return 10.0/1.0;"));
assertEquals(0.0/1.0, exec("return 0.0/1.0;"));
}
public void testDivideByZero() throws Exception {
try {
exec("int x = 1; int y = 0; return x / y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {
// divide by zero
}
try {
exec("long x = 1L; long y = 0L; return x / y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {
// divide by zero
}
}
public void testDivideByZeroConst() throws Exception {
try {
exec("return 1/0;");
fail("should have hit exception");
} catch (ArithmeticException expected) {
// divide by zero
}
try {
exec("return 1L/0L;");
fail("should have hit exception");
} catch (ArithmeticException expected) {
// divide by zero
}
}
}

View File

@ -0,0 +1,184 @@
package org.elasticsearch.plan.a;
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// TODO: Figure out a way to test autobox caching properly from methods such as Integer.valueOf(int);
public class EqualsTests extends ScriptTestCase {
public void testTypesEquals() {
assertEquals(true, exec("return false === false;"));
assertEquals(true, exec("boolean x = false; boolean y = false; return x === y;"));
assertEquals(false, exec("return (byte)3 === (byte)4;"));
assertEquals(true, exec("byte x = 3; byte y = 3; return x === y;"));
assertEquals(false, exec("return (char)3 === (char)4;"));
assertEquals(true, exec("char x = 3; char y = 3; return x === y;"));
assertEquals(false, exec("return (short)3 === (short)4;"));
assertEquals(true, exec("short x = 3; short y = 3; return x === y;"));
assertEquals(false, exec("return (int)3 === (int)4;"));
assertEquals(true, exec("int x = 3; int y = 3; return x === y;"));
assertEquals(false, exec("return (long)3 === (long)4;"));
assertEquals(true, exec("long x = 3; long y = 3; return x === y;"));
assertEquals(false, exec("return (float)3 === (float)4;"));
assertEquals(true, exec("float x = 3; float y = 3; return x === y;"));
assertEquals(false, exec("return (double)3 === (double)4;"));
assertEquals(true, exec("double x = 3; double y = 3; return x === y;"));
assertEquals(true, exec("return false == false;"));
assertEquals(true, exec("boolean x = false; boolean y = false; return x == y;"));
assertEquals(false, exec("return (byte)3 == (byte)4;"));
assertEquals(true, exec("byte x = 3; byte y = 3; return x == y;"));
assertEquals(false, exec("return (char)3 == (char)4;"));
assertEquals(true, exec("char x = 3; char y = 3; return x == y;"));
assertEquals(false, exec("return (short)3 == (short)4;"));
assertEquals(true, exec("short x = 3; short y = 3; return x == y;"));
assertEquals(false, exec("return (int)3 == (int)4;"));
assertEquals(true, exec("int x = 3; int y = 3; return x == y;"));
assertEquals(false, exec("return (long)3 == (long)4;"));
assertEquals(true, exec("long x = 3; long y = 3; return x == y;"));
assertEquals(false, exec("return (float)3 == (float)4;"));
assertEquals(true, exec("float x = 3; float y = 3; return x == y;"));
assertEquals(false, exec("return (double)3 == (double)4;"));
assertEquals(true, exec("double x = 3; double y = 3; return x == y;"));
}
public void testTypesNotEquals() {
assertEquals(false, exec("return true !== true;"));
assertEquals(false, exec("boolean x = false; boolean y = false; return x !== y;"));
assertEquals(true, exec("return (byte)3 !== (byte)4;"));
assertEquals(false, exec("byte x = 3; byte y = 3; return x !== y;"));
assertEquals(true, exec("return (char)3 !== (char)4;"));
assertEquals(false, exec("char x = 3; char y = 3; return x !== y;"));
assertEquals(true, exec("return (short)3 !== (short)4;"));
assertEquals(false, exec("short x = 3; short y = 3; return x !== y;"));
assertEquals(true, exec("return (int)3 !== (int)4;"));
assertEquals(false, exec("int x = 3; int y = 3; return x !== y;"));
assertEquals(true, exec("return (long)3 !== (long)4;"));
assertEquals(false, exec("long x = 3; long y = 3; return x !== y;"));
assertEquals(true, exec("return (float)3 !== (float)4;"));
assertEquals(false, exec("float x = 3; float y = 3; return x !== y;"));
assertEquals(true, exec("return (double)3 !== (double)4;"));
assertEquals(false, exec("double x = 3; double y = 3; return x !== y;"));
assertEquals(false, exec("return true != true;"));
assertEquals(false, exec("boolean x = false; boolean y = false; return x != y;"));
assertEquals(true, exec("return (byte)3 != (byte)4;"));
assertEquals(false, exec("byte x = 3; byte y = 3; return x != y;"));
assertEquals(true, exec("return (char)3 != (char)4;"));
assertEquals(false, exec("char x = 3; char y = 3; return x != y;"));
assertEquals(true, exec("return (short)3 != (short)4;"));
assertEquals(false, exec("short x = 3; short y = 3; return x != y;"));
assertEquals(true, exec("return (int)3 != (int)4;"));
assertEquals(false, exec("int x = 3; int y = 3; return x != y;"));
assertEquals(true, exec("return (long)3 != (long)4;"));
assertEquals(false, exec("long x = 3; long y = 3; return x != y;"));
assertEquals(true, exec("return (float)3 != (float)4;"));
assertEquals(false, exec("float x = 3; float y = 3; return x != y;"));
assertEquals(true, exec("return (double)3 != (double)4;"));
assertEquals(false, exec("double x = 3; double y = 3; return x != y;"));
}
public void testEquals() {
assertEquals(true, exec("return new Long(3) == new Long(3);"));
assertEquals(false, exec("return new Long(3) === new Long(3);"));
assertEquals(true, exec("Integer x = new Integer(3); Object y = x; return x == y;"));
assertEquals(true, exec("Integer x = new Integer(3); Object y = x; return x === y;"));
assertEquals(true, exec("Integer x = new Integer(3); Object y = new Integer(3); return x == y;"));
assertEquals(false, exec("Integer x = new Integer(3); Object y = new Integer(3); return x === y;"));
assertEquals(true, exec("Integer x = new Integer(3); int y = 3; return x == y;"));
assertEquals(true, exec("Integer x = new Integer(3); short y = 3; return x == y;"));
assertEquals(true, exec("Integer x = new Integer(3); Short y = (short)3; return x == y;"));
assertEquals(false, exec("Integer x = new Integer(3); int y = 3; return x === y;"));
assertEquals(false, exec("Integer x = new Integer(3); double y = 3; return x === y;"));
assertEquals(true, exec("int[] x = new int[1]; Object y = x; return x == y;"));
assertEquals(true, exec("int[] x = new int[1]; Object y = x; return x === y;"));
assertEquals(false, exec("int[] x = new int[1]; Object y = new int[1]; return x == y;"));
assertEquals(false, exec("int[] x = new int[1]; Object y = new int[1]; return x === y;"));
assertEquals(false, exec("Map x = new HashMap(); List y = new ArrayList(); return x == y;"));
assertEquals(false, exec("Map x = new HashMap(); List y = new ArrayList(); return x === y;"));
}
public void testNotEquals() {
assertEquals(false, exec("return new Long(3) != new Long(3);"));
assertEquals(true, exec("return new Long(3) !== new Long(3);"));
assertEquals(false, exec("Integer x = new Integer(3); Object y = x; return x != y;"));
assertEquals(false, exec("Integer x = new Integer(3); Object y = x; return x !== y;"));
assertEquals(false, exec("Integer x = new Integer(3); Object y = new Integer(3); return x != y;"));
assertEquals(true, exec("Integer x = new Integer(3); Object y = new Integer(3); return x !== y;"));
assertEquals(true, exec("Integer x = new Integer(3); int y = 3; return x !== y;"));
assertEquals(true, exec("Integer x = new Integer(3); double y = 3; return x !== y;"));
assertEquals(false, exec("int[] x = new int[1]; Object y = x; return x != y;"));
assertEquals(false, exec("int[] x = new int[1]; Object y = x; return x !== y;"));
assertEquals(true, exec("int[] x = new int[1]; Object y = new int[1]; return x != y;"));
assertEquals(true, exec("int[] x = new int[1]; Object y = new int[1]; return x !== y;"));
assertEquals(true, exec("Map x = new HashMap(); List y = new ArrayList(); return x != y;"));
assertEquals(true, exec("Map x = new HashMap(); List y = new ArrayList(); return x !== y;"));
}
public void testBranchEquals() {
assertEquals(0, exec("Character a = 'a'; Character b = 'b'; if (a == b) return 1; else return 0;"));
assertEquals(1, exec("Character a = 'a'; Character b = 'a'; if (a == b) return 1; else return 0;"));
assertEquals(0, exec("Integer a = new Integer(1); Integer b = 1; if (a === b) return 1; else return 0;"));
assertEquals(0, exec("Character a = 'a'; Character b = new Character('a'); if (a === b) return 1; else return 0;"));
assertEquals(1, exec("Character a = 'a'; Object b = a; if (a === b) return 1; else return 0;"));
assertEquals(1, exec("Integer a = 1; Number b = a; Number c = a; if (c === b) return 1; else return 0;"));
assertEquals(0, exec("Integer a = 1; Character b = 'a'; if (a === (Object)b) return 1; else return 0;"));
}
public void testBranchNotEquals() {
assertEquals(1, exec("Character a = 'a'; Character b = 'b'; if (a != b) return 1; else return 0;"));
assertEquals(0, exec("Character a = 'a'; Character b = 'a'; if (a != b) return 1; else return 0;"));
assertEquals(1, exec("Integer a = new Integer(1); Integer b = 1; if (a !== b) return 1; else return 0;"));
assertEquals(1, exec("Character a = 'a'; Character b = new Character('a'); if (a !== b) return 1; else return 0;"));
assertEquals(0, exec("Character a = 'a'; Object b = a; if (a !== b) return 1; else return 0;"));
assertEquals(0, exec("Integer a = 1; Number b = a; Number c = a; if (c !== b) return 1; else return 0;"));
assertEquals(1, exec("Integer a = 1; Character b = 'a'; if (a !== (Object)b) return 1; else return 0;"));
}
public void testRightHandNull() {
assertEquals(false, exec("Character a = 'a'; return a == null;"));
assertEquals(false, exec("Character a = 'a'; return a === null;"));
assertEquals(true, exec("Character a = 'a'; return a != null;"));
assertEquals(true, exec("Character a = 'a'; return a !== null;"));
assertEquals(true, exec("Character a = null; return a == null;"));
assertEquals(false, exec("Character a = null; return a != null;"));
assertEquals(false, exec("Character a = 'a'; Character b = null; return a == b;"));
assertEquals(true, exec("Character a = null; Character b = null; return a === b;"));
assertEquals(true, exec("Character a = 'a'; Character b = null; return a != b;"));
assertEquals(false, exec("Character a = null; Character b = null; return a !== b;"));
assertEquals(false, exec("Integer x = null; double y = 2.0; return x == y;"));
assertEquals(true, exec("Integer x = null; Short y = null; return x == y;"));
}
public void testLeftHandNull() {
assertEquals(false, exec("Character a = 'a'; return null == a;"));
assertEquals(false, exec("Character a = 'a'; return null === a;"));
assertEquals(true, exec("Character a = 'a'; return null != a;"));
assertEquals(true, exec("Character a = 'a'; return null !== a;"));
assertEquals(true, exec("Character a = null; return null == a;"));
assertEquals(false, exec("Character a = null; return null != a;"));
assertEquals(false, exec("Character a = null; Character b = 'a'; return a == b;"));
assertEquals(true, exec("Character a = null; Character b = null; return a == b;"));
assertEquals(true, exec("Character a = null; Character b = null; return b === a;"));
assertEquals(true, exec("Character a = null; Character b = 'a'; return a != b;"));
assertEquals(false, exec("Character a = null; Character b = null; return b != a;"));
assertEquals(false, exec("Character a = null; Character b = null; return b !== a;"));
assertEquals(false, exec("Integer x = null; double y = 2.0; return y == x;"));
assertEquals(true, exec("Integer x = null; Short y = null; return y == x;"));
}
}

View File

@ -0,0 +1,108 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.junit.Before;
public class FieldTests extends ScriptTestCase {
public static class FieldClass {
public boolean z = false;
public byte b = 0;
public short s = 1;
public char c = 'c';
public int i = 2;
public int si = -1;
public long j = 3l;
public float f = 4.0f;
public double d = 5.0;
public String t = "s";
public Object l = new Object();
public float test(float a, float b) {
return Math.min(a, b);
}
public int getSi() {
return si;
}
public void setSi(final int si) {
this.si = si;
}
}
public static class FieldDefinition extends Definition {
FieldDefinition() {
super();
addStruct("FieldClass", FieldClass.class);
addConstructor("FieldClass", "new", new Type[] {}, null);
addField("FieldClass", "z", null, false, booleanType, null);
addField("FieldClass", "b", null, false, byteType, null);
addField("FieldClass", "s", null, false, shortType, null);
addField("FieldClass", "c", null, false, charType, null);
addField("FieldClass", "i", null, false, intType, null);
addField("FieldClass", "j", null, false, longType, null);
addField("FieldClass", "f", null, false, floatType, null);
addField("FieldClass", "d", null, false, doubleType, null);
addField("FieldClass", "t", null, false, stringType, null);
addField("FieldClass", "l", null, false, objectType, null);
addClass("FieldClass");
addMethod("FieldClass", "getSi", null, false, intType, new Type[] {}, null, null);
addMethod("FieldClass", "setSi", null, false, voidType, new Type[] {intType}, null, null);
addMethod("FieldClass", "test", null, false, floatType, new Type[] {floatType, floatType}, null, null);
}
}
@Before
public void setDefinition() {
scriptEngine.setDefinition(new FieldDefinition());
}
public void testIntField() {
assertEquals("s5t42", exec("def fc = new FieldClass() return fc.t += 2 + fc.j + \"t\" + 4 + (3 - 1)"));
assertEquals(2.0f, exec("def fc = new FieldClass(); def l = new Double(3) Byte b = new Byte((byte)2) return fc.test(l, b)"));
assertEquals(4, exec("def fc = new FieldClass() fc.i = 4 return fc.i"));
assertEquals(5, exec("FieldClass fc0 = new FieldClass() FieldClass fc1 = new FieldClass() fc0.i = 7 - fc0.i fc1.i = fc0.i return fc1.i"));
assertEquals(8, exec("def fc0 = new FieldClass() def fc1 = new FieldClass() fc0.i += fc1.i fc0.i += fc0.i return fc0.i"));
}
public void testExplicitShortcut() {
assertEquals(5, exec("FieldClass fc = new FieldClass() fc.setSi(5) return fc.si"));
assertEquals(-1, exec("FieldClass fc = new FieldClass() def x = fc.getSi() x"));
assertEquals(5, exec("FieldClass fc = new FieldClass() fc.si = 5 return fc.si"));
assertEquals(0, exec("FieldClass fc = new FieldClass() fc.si++ return fc.si"));
assertEquals(-1, exec("FieldClass fc = new FieldClass() def x = fc.si++ return x"));
assertEquals(0, exec("FieldClass fc = new FieldClass() def x = ++fc.si return x"));
assertEquals(-2, exec("FieldClass fc = new FieldClass() fc.si *= 2 fc.si"));
assertEquals("-1test", exec("FieldClass fc = new FieldClass() fc.si + \"test\""));
}
public void testImplicitShortcut() {
assertEquals(5, exec("def fc = new FieldClass() fc.setSi(5) return fc.si"));
assertEquals(-1, exec("def fc = new FieldClass() def x = fc.getSi() x"));
assertEquals(5, exec("def fc = new FieldClass() fc.si = 5 return fc.si"));
assertEquals(0, exec("def fc = new FieldClass() fc.si++ return fc.si"));
assertEquals(-1, exec("def fc = new FieldClass() def x = fc.si++ return x"));
assertEquals(0, exec("def fc = new FieldClass() def x = ++fc.si return x"));
assertEquals(-2, exec("def fc = new FieldClass() fc.si *= 2 fc.si"));
assertEquals("-1test", exec("def fc = new FieldClass() fc.si + \"test\""));
}
}

View File

@ -0,0 +1,294 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.elasticsearch.common.settings.Settings;
/** Tests floating point overflow with numeric overflow disabled */
public class FloatOverflowDisabledTests extends ScriptTestCase {
@Override
protected Settings getSettings() {
Settings.Builder builder = Settings.builder();
builder.put(super.getSettings());
builder.put(PlanAScriptEngineService.NUMERIC_OVERFLOW, false);
return builder.build();
}
public void testAssignmentAdditionOverflow() {
// float
try {
exec("float x = 3.4028234663852886E38f; x += 3.4028234663852886E38f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("float x = -3.4028234663852886E38f; x += -3.4028234663852886E38f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
// double
try {
exec("double x = 1.7976931348623157E308; x += 1.7976931348623157E308; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = -1.7976931348623157E308; x += -1.7976931348623157E308; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testAssignmentSubtractionOverflow() {
// float
try {
exec("float x = 3.4028234663852886E38f; x -= -3.4028234663852886E38f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("float x = -3.4028234663852886E38f; x -= 3.4028234663852886E38f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
// double
try {
exec("double x = 1.7976931348623157E308; x -= -1.7976931348623157E308; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = -1.7976931348623157E308; x -= 1.7976931348623157E308; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testAssignmentMultiplicationOverflow() {
// float
try {
exec("float x = 3.4028234663852886E38f; x *= 3.4028234663852886E38f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("float x = 3.4028234663852886E38f; x *= -3.4028234663852886E38f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
// double
try {
exec("double x = 1.7976931348623157E308; x *= 1.7976931348623157E308; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = 1.7976931348623157E308; x *= -1.7976931348623157E308; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testAssignmentDivisionOverflow() {
// float
try {
exec("float x = 3.4028234663852886E38f; x /= 1.401298464324817E-45f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("float x = 3.4028234663852886E38f; x /= -1.401298464324817E-45f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("float x = 1.0f; x /= 0.0f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
// double
try {
exec("double x = 1.7976931348623157E308; x /= 4.9E-324; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = 1.7976931348623157E308; x /= -4.9E-324; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = 1.0f; x /= 0.0; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testAddition() throws Exception {
try {
exec("float x = 3.4028234663852886E38f; float y = 3.4028234663852886E38f; return x + y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = 1.7976931348623157E308; double y = 1.7976931348623157E308; return x + y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testAdditionConst() throws Exception {
try {
exec("return 3.4028234663852886E38f + 3.4028234663852886E38f;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return 1.7976931348623157E308 + 1.7976931348623157E308;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testSubtraction() throws Exception {
try {
exec("float x = -3.4028234663852886E38f; float y = 3.4028234663852886E38f; return x - y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = -1.7976931348623157E308; double y = 1.7976931348623157E308; return x - y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testSubtractionConst() throws Exception {
try {
exec("return -3.4028234663852886E38f - 3.4028234663852886E38f;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return -1.7976931348623157E308 - 1.7976931348623157E308;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testMultiplication() throws Exception {
try {
exec("float x = 3.4028234663852886E38f; float y = 3.4028234663852886E38f; return x * y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = 1.7976931348623157E308; double y = 1.7976931348623157E308; return x * y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testMultiplicationConst() throws Exception {
try {
exec("return 3.4028234663852886E38f * 3.4028234663852886E38f;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return 1.7976931348623157E308 * 1.7976931348623157E308;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testDivision() throws Exception {
try {
exec("float x = 3.4028234663852886E38f; float y = 1.401298464324817E-45f; return x / y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("float x = 1.0f; float y = 0.0f; return x / y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = 1.7976931348623157E308; double y = 4.9E-324; return x / y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = 1.0; double y = 0.0; return x / y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testDivisionConst() throws Exception {
try {
exec("return 3.4028234663852886E38f / 1.401298464324817E-45f;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return 1.0f / 0.0f;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return 1.7976931348623157E308 / 4.9E-324;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return 1.0 / 0.0;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testDivisionNaN() throws Exception {
// float division, constant division, and assignment
try {
exec("float x = 0f; float y = 0f; return x / y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return 0f / 0f;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("float x = 0f; x /= 0f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
// double division, constant division, and assignment
try {
exec("double x = 0.0; double y = 0.0; return x / y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return 0.0 / 0.0;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = 0.0; x /= 0.0; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
public void testRemainderNaN() throws Exception {
// float division, constant division, and assignment
try {
exec("float x = 1f; float y = 0f; return x % y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return 1f % 0f;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("float x = 1f; x %= 0f; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
// double division, constant division, and assignment
try {
exec("double x = 1.0; double y = 0.0; return x % y;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("return 1.0 % 0.0;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
try {
exec("double x = 1.0; x %= 0.0; return x;");
fail("didn't hit expected exception");
} catch (ArithmeticException expected) {}
}
}

View File

@ -0,0 +1,144 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.elasticsearch.common.settings.Settings;
/** Tests floating point overflow with numeric overflow enabled */
public class FloatOverflowEnabledTests extends ScriptTestCase {
@Override
protected Settings getSettings() {
Settings.Builder builder = Settings.builder();
builder.put(super.getSettings());
builder.put(PlanAScriptEngineService.NUMERIC_OVERFLOW, true);
return builder.build();
}
public void testAssignmentAdditionOverflow() {
// float
assertEquals(Float.POSITIVE_INFINITY, exec("float x = 3.4028234663852886E38f; x += 3.4028234663852886E38f; return x;"));
assertEquals(Float.NEGATIVE_INFINITY, exec("float x = -3.4028234663852886E38f; x += -3.4028234663852886E38f; return x;"));
// double
assertEquals(Double.POSITIVE_INFINITY, exec("double x = 1.7976931348623157E308; x += 1.7976931348623157E308; return x;"));
assertEquals(Double.NEGATIVE_INFINITY, exec("double x = -1.7976931348623157E308; x += -1.7976931348623157E308; return x;"));
}
public void testAssignmentSubtractionOverflow() {
// float
assertEquals(Float.POSITIVE_INFINITY, exec("float x = 3.4028234663852886E38f; x -= -3.4028234663852886E38f; return x;"));
assertEquals(Float.NEGATIVE_INFINITY, exec("float x = -3.4028234663852886E38f; x -= 3.4028234663852886E38f; return x;"));
// double
assertEquals(Double.POSITIVE_INFINITY, exec("double x = 1.7976931348623157E308; x -= -1.7976931348623157E308; return x;"));
assertEquals(Double.NEGATIVE_INFINITY, exec("double x = -1.7976931348623157E308; x -= 1.7976931348623157E308; return x;"));
}
public void testAssignmentMultiplicationOverflow() {
// float
assertEquals(Float.POSITIVE_INFINITY, exec("float x = 3.4028234663852886E38f; x *= 3.4028234663852886E38f; return x;"));
assertEquals(Float.NEGATIVE_INFINITY, exec("float x = 3.4028234663852886E38f; x *= -3.4028234663852886E38f; return x;"));
// double
assertEquals(Double.POSITIVE_INFINITY, exec("double x = 1.7976931348623157E308; x *= 1.7976931348623157E308; return x;"));
assertEquals(Double.NEGATIVE_INFINITY, exec("double x = 1.7976931348623157E308; x *= -1.7976931348623157E308; return x;"));
}
public void testAssignmentDivisionOverflow() {
// float
assertEquals(Float.POSITIVE_INFINITY, exec("float x = 3.4028234663852886E38f; x /= 1.401298464324817E-45f; return x;"));
assertEquals(Float.NEGATIVE_INFINITY, exec("float x = 3.4028234663852886E38f; x /= -1.401298464324817E-45f; return x;"));
assertEquals(Float.POSITIVE_INFINITY, exec("float x = 1.0f; x /= 0.0f; return x;"));
// double
assertEquals(Double.POSITIVE_INFINITY, exec("double x = 1.7976931348623157E308; x /= 4.9E-324; return x;"));
assertEquals(Double.NEGATIVE_INFINITY, exec("double x = 1.7976931348623157E308; x /= -4.9E-324; return x;"));
assertEquals(Double.POSITIVE_INFINITY, exec("double x = 1.0f; x /= 0.0; return x;"));
}
public void testAddition() throws Exception {
assertEquals(Float.POSITIVE_INFINITY, exec("float x = 3.4028234663852886E38f; float y = 3.4028234663852886E38f; return x + y;"));
assertEquals(Double.POSITIVE_INFINITY, exec("double x = 1.7976931348623157E308; double y = 1.7976931348623157E308; return x + y;"));
}
public void testAdditionConst() throws Exception {
assertEquals(Float.POSITIVE_INFINITY, exec("return 3.4028234663852886E38f + 3.4028234663852886E38f;"));
assertEquals(Double.POSITIVE_INFINITY, exec("return 1.7976931348623157E308 + 1.7976931348623157E308;"));
}
public void testSubtraction() throws Exception {
assertEquals(Float.NEGATIVE_INFINITY, exec("float x = -3.4028234663852886E38f; float y = 3.4028234663852886E38f; return x - y;"));
assertEquals(Double.NEGATIVE_INFINITY, exec("double x = -1.7976931348623157E308; double y = 1.7976931348623157E308; return x - y;"));
}
public void testSubtractionConst() throws Exception {
assertEquals(Float.NEGATIVE_INFINITY, exec("return -3.4028234663852886E38f - 3.4028234663852886E38f;"));
assertEquals(Double.NEGATIVE_INFINITY, exec("return -1.7976931348623157E308 - 1.7976931348623157E308;"));
}
public void testMultiplication() throws Exception {
assertEquals(Float.POSITIVE_INFINITY, exec("float x = 3.4028234663852886E38f; float y = 3.4028234663852886E38f; return x * y;"));
assertEquals(Double.POSITIVE_INFINITY, exec("double x = 1.7976931348623157E308; double y = 1.7976931348623157E308; return x * y;"));
}
public void testMultiplicationConst() throws Exception {
assertEquals(Float.POSITIVE_INFINITY, exec("return 3.4028234663852886E38f * 3.4028234663852886E38f;"));
assertEquals(Double.POSITIVE_INFINITY, exec("return 1.7976931348623157E308 * 1.7976931348623157E308;"));
}
public void testDivision() throws Exception {
assertEquals(Float.POSITIVE_INFINITY, exec("float x = 3.4028234663852886E38f; float y = 1.401298464324817E-45f; return x / y;"));
assertEquals(Float.POSITIVE_INFINITY, exec("float x = 1.0f; float y = 0.0f; return x / y;"));
assertEquals(Double.POSITIVE_INFINITY, exec("double x = 1.7976931348623157E308; double y = 4.9E-324; return x / y;"));
assertEquals(Double.POSITIVE_INFINITY, exec("double x = 1.0; double y = 0.0; return x / y;"));
}
public void testDivisionConst() throws Exception {
assertEquals(Float.POSITIVE_INFINITY, exec("return 3.4028234663852886E38f / 1.401298464324817E-45f;"));
assertEquals(Float.POSITIVE_INFINITY, exec("return 1.0f / 0.0f;"));
assertEquals(Double.POSITIVE_INFINITY, exec("return 1.7976931348623157E308 / 4.9E-324;"));
assertEquals(Double.POSITIVE_INFINITY, exec("return 1.0 / 0.0;"));
}
public void testDivisionNaN() throws Exception {
// float division, constant division, and assignment
assertTrue(Float.isNaN((Float) exec("float x = 0f; float y = 0f; return x / y;")));
assertTrue(Float.isNaN((Float) exec("return 0f / 0f;")));
assertTrue(Float.isNaN((Float) exec("float x = 0f; x /= 0f; return x;")));
// double division, constant division, and assignment
assertTrue(Double.isNaN((Double) exec("double x = 0.0; double y = 0.0; return x / y;")));
assertTrue(Double.isNaN((Double) exec("return 0.0 / 0.0;")));
assertTrue(Double.isNaN((Double) exec("double x = 0.0; x /= 0.0; return x;")));
}
public void testRemainderNaN() throws Exception {
// float division, constant division, and assignment
assertTrue(Float.isNaN((Float) exec("float x = 1f; float y = 0f; return x % y;")));
assertTrue(Float.isNaN((Float) exec("return 1f % 0f;")));
assertTrue(Float.isNaN((Float) exec("float x = 1f; x %= 0f; return x;")));
// double division, constant division, and assignment
assertTrue(Double.isNaN((Double) exec("double x = 1.0; double y = 0.0; return x % y;")));
assertTrue(Double.isNaN((Double) exec("return 1.0 % 0.0;")));
assertTrue(Double.isNaN((Double) exec("double x = 1.0; x %= 0.0; return x;")));
}
}

View File

@ -0,0 +1,79 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/** Tests for increment/decrement operators across all data types */
public class IncrementTests extends ScriptTestCase {
/** incrementing byte values */
public void testIncrementByte() {
assertEquals((byte)0, exec("byte x = (byte)0; return x++;"));
assertEquals((byte)0, exec("byte x = (byte)0; return x--;"));
assertEquals((byte)1, exec("byte x = (byte)0; return ++x;"));
assertEquals((byte)-1, exec("byte x = (byte)0; return --x;"));
}
/** incrementing char values */
public void testIncrementChar() {
assertEquals((char)0, exec("char x = (char)0; return x++;"));
assertEquals((char)1, exec("char x = (char)1; return x--;"));
assertEquals((char)1, exec("char x = (char)0; return ++x;"));
}
/** incrementing short values */
public void testIncrementShort() {
assertEquals((short)0, exec("short x = (short)0; return x++;"));
assertEquals((short)0, exec("short x = (short)0; return x--;"));
assertEquals((short)1, exec("short x = (short)0; return ++x;"));
assertEquals((short)-1, exec("short x = (short)0; return --x;"));
}
/** incrementing integer values */
public void testIncrementInt() {
assertEquals(0, exec("int x = 0; return x++;"));
assertEquals(0, exec("int x = 0; return x--;"));
assertEquals(1, exec("int x = 0; return ++x;"));
assertEquals(-1, exec("int x = 0; return --x;"));
}
/** incrementing long values */
public void testIncrementLong() {
assertEquals(0L, exec("long x = 0; return x++;"));
assertEquals(0L, exec("long x = 0; return x--;"));
assertEquals(1L, exec("long x = 0; return ++x;"));
assertEquals(-1L, exec("long x = 0; return --x;"));
}
/** incrementing float values */
public void testIncrementFloat() {
assertEquals(0F, exec("float x = 0F; return x++;"));
assertEquals(0F, exec("float x = 0F; return x--;"));
assertEquals(1F, exec("float x = 0F; return ++x;"));
assertEquals(-1F, exec("float x = 0F; return --x;"));
}
/** incrementing double values */
public void testIncrementDouble() {
assertEquals(0D, exec("double x = 0.0; return x++;"));
assertEquals(0D, exec("double x = 0.0; return x--;"));
assertEquals(1D, exec("double x = 0.0; return ++x;"));
assertEquals(-1D, exec("double x = 0.0; return --x;"));
}
}

View File

@ -0,0 +1,445 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.elasticsearch.common.settings.Settings;
/** Tests integer overflow with numeric overflow disabled */
public class IntegerOverflowDisabledTests extends ScriptTestCase {
@Override
protected Settings getSettings() {
Settings.Builder builder = Settings.builder();
builder.put(super.getSettings());
builder.put(PlanAScriptEngineService.NUMERIC_OVERFLOW, false);
return builder.build();
}
public void testAssignmentAdditionOverflow() {
// byte
try {
exec("byte x = 0; x += 128; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("byte x = 0; x += -129; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// short
try {
exec("short x = 0; x += 32768; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("byte x = 0; x += -32769; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// char
try {
exec("char x = 0; x += 65536; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("char x = 0; x += -65536; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// int
try {
exec("int x = 1; x += 2147483647; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("int x = -2; x += -2147483647; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// long
try {
exec("long x = 1; x += 9223372036854775807L; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = -2; x += -9223372036854775807L; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testAssignmentSubtractionOverflow() {
// byte
try {
exec("byte x = 0; x -= -128; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("byte x = 0; x -= 129; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// short
try {
exec("short x = 0; x -= -32768; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("byte x = 0; x -= 32769; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// char
try {
exec("char x = 0; x -= -65536; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("char x = 0; x -= 65536; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// int
try {
exec("int x = 1; x -= -2147483647; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("int x = -2; x -= 2147483647; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// long
try {
exec("long x = 1; x -= -9223372036854775807L; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = -2; x -= 9223372036854775807L; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testAssignmentMultiplicationOverflow() {
// byte
try {
exec("byte x = 2; x *= 128; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("byte x = 2; x *= -128; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// char
try {
exec("char x = 2; x *= 65536; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("char x = 2; x *= -65536; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// int
try {
exec("int x = 2; x *= 2147483647; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("int x = 2; x *= -2147483647; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// long
try {
exec("long x = 2; x *= 9223372036854775807L; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = 2; x *= -9223372036854775807L; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testAssignmentDivisionOverflow() {
// byte
try {
exec("byte x = (byte) -128; x /= -1; return x;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
// short
try {
exec("short x = (short) -32768; x /= -1; return x;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
// cannot happen for char: unsigned
// int
try {
exec("int x = -2147483647 - 1; x /= -1; return x;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
// long
try {
exec("long x = -9223372036854775807L - 1L; x /=-1L; return x;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testIncrementOverFlow() throws Exception {
// byte
try {
exec("byte x = 127; ++x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("byte x = 127; x++; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("byte x = (byte) -128; --x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("byte x = (byte) -128; x--; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// short
try {
exec("short x = 32767; ++x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("short x = 32767; x++; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("short x = (short) -32768; --x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("short x = (short) -32768; x--; return x;");
} catch (ArithmeticException expected) {}
// char
try {
exec("char x = 65535; ++x; return x;");
} catch (ArithmeticException expected) {}
try {
exec("char x = 65535; x++; return x;");
} catch (ArithmeticException expected) {}
try {
exec("char x = (char) 0; --x; return x;");
} catch (ArithmeticException expected) {}
try {
exec("char x = (char) 0; x--; return x;");
} catch (ArithmeticException expected) {}
// int
try {
exec("int x = 2147483647; ++x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("int x = 2147483647; x++; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("int x = (int) -2147483648L; --x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("int x = (int) -2147483648L; x--; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
// long
try {
exec("long x = 9223372036854775807L; ++x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = 9223372036854775807L; x++; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = -9223372036854775807L - 1L; --x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = -9223372036854775807L - 1L; x--; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testAddition() throws Exception {
try {
exec("int x = 2147483647; int y = 2147483647; return x + y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = 9223372036854775807L; long y = 9223372036854775807L; return x + y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testAdditionConst() throws Exception {
try {
exec("return 2147483647 + 2147483647;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
try {
exec("return 9223372036854775807L + 9223372036854775807L;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testSubtraction() throws Exception {
try {
exec("int x = -10; int y = 2147483647; return x - y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = -10L; long y = 9223372036854775807L; return x - y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testSubtractionConst() throws Exception {
try {
exec("return -10 - 2147483647;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
try {
exec("return -10L - 9223372036854775807L;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testMultiplication() throws Exception {
try {
exec("int x = 2147483647; int y = 2147483647; return x * y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = 9223372036854775807L; long y = 9223372036854775807L; return x * y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testMultiplicationConst() throws Exception {
try {
exec("return 2147483647 * 2147483647;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
try {
exec("return 9223372036854775807L * 9223372036854775807L;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testDivision() throws Exception {
try {
exec("int x = -2147483647 - 1; int y = -1; return x / y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = -9223372036854775808L; long y = -1L; return x / y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testDivisionConst() throws Exception {
try {
exec("return (-2147483648) / -1;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
try {
exec("return (-9223372036854775808L) / -1L;");
fail("should have hit exception");
} catch (ArithmeticException expected) {}
}
public void testNegationOverflow() throws Exception {
try {
exec("int x = -2147483648; x = -x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = -9223372036854775808L; x = -x; return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testNegationOverflowConst() throws Exception {
try {
exec("int x = -(-2147483648); return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
exec("long x = -(-9223372036854775808L); return x;");
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
}

View File

@ -0,0 +1,194 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.elasticsearch.common.settings.Settings;
/** Tests integer overflow with numeric overflow enabled */
public class IntegerOverflowEnabledTests extends ScriptTestCase {
@Override
protected Settings getSettings() {
Settings.Builder builder = Settings.builder();
builder.put(super.getSettings());
builder.put(PlanAScriptEngineService.NUMERIC_OVERFLOW, true);
return builder.build();
}
public void testAssignmentAdditionOverflow() {
// byte
assertEquals((byte)(0 + 128), exec("byte x = 0; x += 128; return x;"));
assertEquals((byte)(0 + -129), exec("byte x = 0; x += -129; return x;"));
// short
assertEquals((short)(0 + 32768), exec("short x = 0; x += 32768; return x;"));
assertEquals((short)(0 + -32769), exec("short x = 0; x += -32769; return x;"));
// char
assertEquals((char)(0 + 65536), exec("char x = 0; x += 65536; return x;"));
assertEquals((char)(0 + -65536), exec("char x = 0; x += -65536; return x;"));
// int
assertEquals(1 + 2147483647, exec("int x = 1; x += 2147483647; return x;"));
assertEquals(-2 + -2147483647, exec("int x = -2; x += -2147483647; return x;"));
// long
assertEquals(1L + 9223372036854775807L, exec("long x = 1; x += 9223372036854775807L; return x;"));
assertEquals(-2L + -9223372036854775807L, exec("long x = -2; x += -9223372036854775807L; return x;"));
}
public void testAssignmentSubtractionOverflow() {
// byte
assertEquals((byte)(0 - -128), exec("byte x = 0; x -= -128; return x;"));
assertEquals((byte)(0 - 129), exec("byte x = 0; x -= 129; return x;"));
// short
assertEquals((short)(0 - -32768), exec("short x = 0; x -= -32768; return x;"));
assertEquals((short)(0 - 32769), exec("short x = 0; x -= 32769; return x;"));
// char
assertEquals((char)(0 - -65536), exec("char x = 0; x -= -65536; return x;"));
assertEquals((char)(0 - 65536), exec("char x = 0; x -= 65536; return x;"));
// int
assertEquals(1 - -2147483647, exec("int x = 1; x -= -2147483647; return x;"));
assertEquals(-2 - 2147483647, exec("int x = -2; x -= 2147483647; return x;"));
// long
assertEquals(1L - -9223372036854775807L, exec("long x = 1; x -= -9223372036854775807L; return x;"));
assertEquals(-2L - 9223372036854775807L, exec("long x = -2; x -= 9223372036854775807L; return x;"));
}
public void testAssignmentMultiplicationOverflow() {
// byte
assertEquals((byte) (2 * 128), exec("byte x = 2; x *= 128; return x;"));
assertEquals((byte) (2 * -128), exec("byte x = 2; x *= -128; return x;"));
// char
assertEquals((char) (2 * 65536), exec("char x = 2; x *= 65536; return x;"));
assertEquals((char) (2 * -65536), exec("char x = 2; x *= -65536; return x;"));
// int
assertEquals(2 * 2147483647, exec("int x = 2; x *= 2147483647; return x;"));
assertEquals(2 * -2147483647, exec("int x = 2; x *= -2147483647; return x;"));
// long
assertEquals(2L * 9223372036854775807L, exec("long x = 2; x *= 9223372036854775807L; return x;"));
assertEquals(2L * -9223372036854775807L, exec("long x = 2; x *= -9223372036854775807L; return x;"));
}
public void testAssignmentDivisionOverflow() {
// byte
assertEquals((byte) (-128 / -1), exec("byte x = (byte) -128; x /= -1; return x;"));
// short
assertEquals((short) (-32768 / -1), exec("short x = (short) -32768; x /= -1; return x;"));
// cannot happen for char: unsigned
// int
assertEquals((-2147483647 - 1) / -1, exec("int x = -2147483647 - 1; x /= -1; return x;"));
// long
assertEquals((-9223372036854775807L - 1L) / -1L, exec("long x = -9223372036854775807L - 1L; x /=-1L; return x;"));
}
public void testIncrementOverFlow() throws Exception {
// byte
assertEquals((byte) 128, exec("byte x = 127; ++x; return x;"));
assertEquals((byte) 128, exec("byte x = 127; x++; return x;"));
assertEquals((byte) -129, exec("byte x = (byte) -128; --x; return x;"));
assertEquals((byte) -129, exec("byte x = (byte) -128; x--; return x;"));
// short
assertEquals((short) 32768, exec("short x = 32767; ++x; return x;"));
assertEquals((short) 32768, exec("short x = 32767; x++; return x;"));
assertEquals((short) -32769, exec("short x = (short) -32768; --x; return x;"));
assertEquals((short) -32769, exec("short x = (short) -32768; x--; return x;"));
// char
assertEquals((char) 65536, exec("char x = 65535; ++x; return x;"));
assertEquals((char) 65536, exec("char x = 65535; x++; return x;"));
assertEquals((char) -1, exec("char x = (char) 0; --x; return x;"));
assertEquals((char) -1, exec("char x = (char) 0; x--; return x;"));
// int
assertEquals(2147483647 + 1, exec("int x = 2147483647; ++x; return x;"));
assertEquals(2147483647 + 1, exec("int x = 2147483647; x++; return x;"));
assertEquals(-2147483648 - 1, exec("int x = (int) -2147483648L; --x; return x;"));
assertEquals(-2147483648 - 1, exec("int x = (int) -2147483648L; x--; return x;"));
// long
assertEquals(9223372036854775807L + 1L, exec("long x = 9223372036854775807L; ++x; return x;"));
assertEquals(9223372036854775807L + 1L, exec("long x = 9223372036854775807L; x++; return x;"));
assertEquals(-9223372036854775807L - 1L - 1L, exec("long x = -9223372036854775807L - 1L; --x; return x;"));
assertEquals(-9223372036854775807L - 1L - 1L, exec("long x = -9223372036854775807L - 1L; x--; return x;"));
}
public void testAddition() throws Exception {
assertEquals(2147483647 + 2147483647, exec("int x = 2147483647; int y = 2147483647; return x + y;"));
assertEquals(9223372036854775807L + 9223372036854775807L, exec("long x = 9223372036854775807L; long y = 9223372036854775807L; return x + y;"));
}
public void testAdditionConst() throws Exception {
assertEquals(2147483647 + 2147483647, exec("return 2147483647 + 2147483647;"));
assertEquals(9223372036854775807L + 9223372036854775807L, exec("return 9223372036854775807L + 9223372036854775807L;"));
}
public void testSubtraction() throws Exception {
assertEquals(-10 - 2147483647, exec("int x = -10; int y = 2147483647; return x - y;"));
assertEquals(-10L - 9223372036854775807L, exec("long x = -10L; long y = 9223372036854775807L; return x - y;"));
}
public void testSubtractionConst() throws Exception {
assertEquals(-10 - 2147483647, exec("return -10 - 2147483647;"));
assertEquals(-10L - 9223372036854775807L, exec("return -10L - 9223372036854775807L;"));
}
public void testMultiplication() throws Exception {
assertEquals(2147483647 * 2147483647, exec("int x = 2147483647; int y = 2147483647; return x * y;"));
assertEquals(9223372036854775807L * 9223372036854775807L, exec("long x = 9223372036854775807L; long y = 9223372036854775807L; return x * y;"));
}
public void testMultiplicationConst() throws Exception {
assertEquals(2147483647 * 2147483647, exec("return 2147483647 * 2147483647;"));
assertEquals(9223372036854775807L * 9223372036854775807L, exec("return 9223372036854775807L * 9223372036854775807L;"));
}
public void testDivision() throws Exception {
assertEquals((-2147483647 - 1) / -1, exec("int x = -2147483648; int y = -1; return x / y;"));
assertEquals((-9223372036854775807L - 1L) / -1L, exec("long x = -9223372036854775808L; long y = -1L; return x / y;"));
}
public void testDivisionConst() throws Exception {
assertEquals((-2147483647 - 1) / -1, exec("return (-2147483648) / -1;"));
assertEquals((-9223372036854775807L - 1L) / -1L, exec("return (-9223372036854775808L) / -1L;"));
}
public void testNegationOverflow() throws Exception {
assertEquals(-(-2147483647 - 1), exec("int x = -2147483648; x = -x; return x;"));
assertEquals(-(-9223372036854775807L - 1L), exec("long x = -9223372036854775808L; x = -x; return x;"));
}
public void testNegationOverflowConst() throws Exception {
assertEquals(-(-2147483647 - 1), exec("int x = -(-2147483648); return x;"));
assertEquals(-(-9223372036854775807L - 1L), exec("long x = -(-9223372036854775808L); return x;"));
}
}

View File

@ -0,0 +1,126 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/** Tests for multiplication operator across all types */
//TODO: NaN/Inf/overflow/...
public class MultiplicationTests extends ScriptTestCase {
// TODO: short,byte,char
public void testInt() throws Exception {
assertEquals(1*1, exec("int x = 1; int y = 1; return x*y;"));
assertEquals(2*3, exec("int x = 2; int y = 3; return x*y;"));
assertEquals(5*10, exec("int x = 5; int y = 10; return x*y;"));
assertEquals(1*1*2, exec("int x = 1; int y = 1; int z = 2; return x*y*z;"));
assertEquals((1*1)*2, exec("int x = 1; int y = 1; int z = 2; return (x*y)*z;"));
assertEquals(1*(1*2), exec("int x = 1; int y = 1; int z = 2; return x*(y*z);"));
assertEquals(10*0, exec("int x = 10; int y = 0; return x*y;"));
assertEquals(0*0, exec("int x = 0; int y = 0; return x*x;"));
}
public void testIntConst() throws Exception {
assertEquals(1*1, exec("return 1*1;"));
assertEquals(2*3, exec("return 2*3;"));
assertEquals(5*10, exec("return 5*10;"));
assertEquals(1*1*2, exec("return 1*1*2;"));
assertEquals((1*1)*2, exec("return (1*1)*2;"));
assertEquals(1*(1*2), exec("return 1*(1*2);"));
assertEquals(10*0, exec("return 10*0;"));
assertEquals(0*0, exec("return 0*0;"));
}
public void testByte() throws Exception {
assertEquals((byte)1*(byte)1, exec("byte x = 1; byte y = 1; return x*y;"));
assertEquals((byte)2*(byte)3, exec("byte x = 2; byte y = 3; return x*y;"));
assertEquals((byte)5*(byte)10, exec("byte x = 5; byte y = 10; return x*y;"));
assertEquals((byte)1*(byte)1*(byte)2, exec("byte x = 1; byte y = 1; byte z = 2; return x*y*z;"));
assertEquals(((byte)1*(byte)1)*(byte)2, exec("byte x = 1; byte y = 1; byte z = 2; return (x*y)*z;"));
assertEquals((byte)1*((byte)1*(byte)2), exec("byte x = 1; byte y = 1; byte z = 2; return x*(y*z);"));
assertEquals((byte)10*(byte)0, exec("byte x = 10; byte y = 0; return x*y;"));
assertEquals((byte)0*(byte)0, exec("byte x = 0; byte y = 0; return x*x;"));
}
public void testLong() throws Exception {
assertEquals(1L*1L, exec("long x = 1; long y = 1; return x*y;"));
assertEquals(2L*3L, exec("long x = 2; long y = 3; return x*y;"));
assertEquals(5L*10L, exec("long x = 5; long y = 10; return x*y;"));
assertEquals(1L*1L*2L, exec("long x = 1; long y = 1; int z = 2; return x*y*z;"));
assertEquals((1L*1L)*2L, exec("long x = 1; long y = 1; int z = 2; return (x*y)*z;"));
assertEquals(1L*(1L*2L), exec("long x = 1; long y = 1; int z = 2; return x*(y*z);"));
assertEquals(10L*0L, exec("long x = 10; long y = 0; return x*y;"));
assertEquals(0L*0L, exec("long x = 0; long y = 0; return x*x;"));
}
public void testLongConst() throws Exception {
assertEquals(1L*1L, exec("return 1L*1L;"));
assertEquals(2L*3L, exec("return 2L*3L;"));
assertEquals(5L*10L, exec("return 5L*10L;"));
assertEquals(1L*1L*2L, exec("return 1L*1L*2L;"));
assertEquals((1L*1L)*2L, exec("return (1L*1L)*2L;"));
assertEquals(1L*(1L*2L), exec("return 1L*(1L*2L);"));
assertEquals(10L*0L, exec("return 10L*0L;"));
assertEquals(0L*0L, exec("return 0L*0L;"));
}
public void testFloat() throws Exception {
assertEquals(1F*1F, exec("float x = 1; float y = 1; return x*y;"));
assertEquals(2F*3F, exec("float x = 2; float y = 3; return x*y;"));
assertEquals(5F*10F, exec("float x = 5; float y = 10; return x*y;"));
assertEquals(1F*1F*2F, exec("float x = 1; float y = 1; float z = 2; return x*y*z;"));
assertEquals((1F*1F)*2F, exec("float x = 1; float y = 1; float z = 2; return (x*y)*z;"));
assertEquals(1F*(1F*2F), exec("float x = 1; float y = 1; float z = 2; return x*(y*z);"));
assertEquals(10F*0F, exec("float x = 10; float y = 0; return x*y;"));
assertEquals(0F*0F, exec("float x = 0; float y = 0; return x*x;"));
}
public void testFloatConst() throws Exception {
assertEquals(1F*1F, exec("return 1F*1F;"));
assertEquals(2F*3F, exec("return 2F*3F;"));
assertEquals(5F*10F, exec("return 5F*10F;"));
assertEquals(1F*1F*2F, exec("return 1F*1F*2F;"));
assertEquals((1F*1F)*2F, exec("return (1F*1F)*2F;"));
assertEquals(1F*(1F*2F), exec("return 1F*(1F*2F);"));
assertEquals(10F*0F, exec("return 10F*0F;"));
assertEquals(0F*0F, exec("return 0F*0F;"));
}
public void testDouble() throws Exception {
assertEquals(1D*1D, exec("double x = 1; double y = 1; return x*y;"));
assertEquals(2D*3D, exec("double x = 2; double y = 3; return x*y;"));
assertEquals(5D*10D, exec("double x = 5; double y = 10; return x*y;"));
assertEquals(1D*1D*2D, exec("double x = 1; double y = 1; double z = 2; return x*y*z;"));
assertEquals((1D*1D)*2D, exec("double x = 1; double y = 1; double z = 2; return (x*y)*z;"));
assertEquals(1D*(1D*2D), exec("double x = 1; double y = 1; double z = 2; return x*(y*z);"));
assertEquals(10D*0D, exec("double x = 10; float y = 0; return x*y;"));
assertEquals(0D*0D, exec("double x = 0; float y = 0; return x*x;"));
}
public void testDoubleConst() throws Exception {
assertEquals(1.0*1.0, exec("return 1.0*1.0;"));
assertEquals(2.0*3.0, exec("return 2.0*3.0;"));
assertEquals(5.0*10.0, exec("return 5.0*10.0;"));
assertEquals(1.0*1.0*2.0, exec("return 1.0*1.0*2.0;"));
assertEquals((1.0*1.0)*2.0, exec("return (1.0*1.0)*2.0;"));
assertEquals(1.0*(1.0*2.0), exec("return 1.0*(1.0*2.0);"));
assertEquals(10.0*0.0, exec("return 10.0*0.0;"));
assertEquals(0.0*0.0, exec("return 0.0*0.0;"));
}
}

View File

@ -0,0 +1,178 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import java.util.HashMap;
import java.util.Map;
public class NoSemiColonTest extends ScriptTestCase {
public void testIfStatement() {
assertEquals(1, exec("int x = 5 if (x == 5) return 1 return 0"));
assertEquals(0, exec("int x = 4 if (x == 5) return 1 else return 0"));
assertEquals(2, exec("int x = 4 if (x == 5) return 1 else if (x == 4) return 2 else return 0"));
assertEquals(1, exec("int x = 4 if (x == 5) return 1 else if (x == 4) return 1 else return 0"));
assertEquals(3, exec(
"int x = 5\n" +
"if (x == 5) {\n" +
" int y = 2\n" +
" \n" +
" if (y == 2) {\n" +
" x = 3\n" +
" }\n" +
" \n" +
"}\n" +
"\n" +
"return x\n"));
}
public void testWhileStatement() {
assertEquals("aaaaaa", exec("String c = \"a\" int x while (x < 5) { c ..= \"a\" ++x } return c"));
Object value = exec(
" byte[][] b = new byte[5][5] \n" +
" byte x = 0, y \n" +
" \n" +
" while (x < 5) { \n" +
" y = 0 \n" +
" \n" +
" while (y < 5) { \n" +
" b[x][y] = (byte)(x*y) \n" +
" ++y \n" +
" } \n" +
" \n" +
" ++x \n" +
" } \n" +
" \n" +
" return b \n");
byte[][] b = (byte[][])value;
for (byte x = 0; x < 5; ++x) {
for (byte y = 0; y < 5; ++y) {
assertEquals(x*y, b[x][y]);
}
}
}
public void testDoWhileStatement() {
assertEquals("aaaaaa", exec("String c = \"a\" int x do { c ..= \"a\" ++x } while (x < 5) return c"));
Object value = exec(
" long[][] l = new long[5][5] \n" +
" long x = 0, y \n" +
" \n" +
" do { \n" +
" y = 0 \n" +
" \n" +
" do { \n" +
" l[(int)x][(int)y] = x*y \n" +
" ++y \n" +
" } while (y < 5) \n" +
" \n" +
" ++x \n" +
" } while (x < 5) \n" +
" \n" +
" return l \n");
long[][] l = (long[][])value;
for (long x = 0; x < 5; ++x) {
for (long y = 0; y < 5; ++y) {
assertEquals(x*y, l[(int)x][(int)y]);
}
}
}
public void testForStatement() {
assertEquals("aaaaaa", exec("String c = \"a\" for (int x = 0; x < 5; ++x) c ..= \"a\" return c"));
Object value = exec(
" int[][] i = new int[5][5] \n" +
" for (int x = 0; x < 5; ++x) { \n" +
" for (int y = 0; y < 5; ++y) { \n" +
" i[x][y] = x*y \n" +
" } \n" +
" } \n" +
" \n" +
" return i \n");
int[][] i = (int[][])value;
for (int x = 0; x < 5; ++x) {
for (int y = 0; y < 5; ++y) {
assertEquals(x*y, i[x][y]);
}
}
}
public void testDeclarationStatement() {
assertEquals((byte)2, exec("byte a = 2 return a"));
assertEquals((short)2, exec("short a = 2 return a"));
assertEquals((char)2, exec("char a = 2 return a"));
assertEquals(2, exec("int a = 2 return a"));
assertEquals(2L, exec("long a = 2 return a"));
assertEquals(2F, exec("float a = 2 return a"));
assertEquals(2.0, exec("double a = 2 return a"));
assertEquals(false, exec("boolean a = false return a"));
assertEquals("string", exec("String a = \"string\" return a"));
assertEquals(HashMap.class, exec("Map<String, Object> a = new HashMap<String, Object>() return a").getClass());
assertEquals(byte[].class, exec("byte[] a = new byte[1] return a").getClass());
assertEquals(short[].class, exec("short[] a = new short[1] return a").getClass());
assertEquals(char[].class, exec("char[] a = new char[1] return a").getClass());
assertEquals(int[].class, exec("int[] a = new int[1] return a").getClass());
assertEquals(long[].class, exec("long[] a = new long[1] return a").getClass());
assertEquals(float[].class, exec("float[] a = new float[1] return a").getClass());
assertEquals(double[].class, exec("double[] a = new double[1] return a").getClass());
assertEquals(boolean[].class, exec("boolean[] a = new boolean[1] return a").getClass());
assertEquals(String[].class, exec("String[] a = new String[1] return a").getClass());
assertEquals(Map[].class, exec("Map<String,Object>[] a = new Map<String,Object>[1] return a").getClass());
assertEquals(byte[][].class, exec("byte[][] a = new byte[1][2] return a").getClass());
assertEquals(short[][][].class, exec("short[][][] a = new short[1][2][3] return a").getClass());
assertEquals(char[][][][].class, exec("char[][][][] a = new char[1][2][3][4] return a").getClass());
assertEquals(int[][][][][].class, exec("int[][][][][] a = new int[1][2][3][4][5] return a").getClass());
assertEquals(long[][].class, exec("long[][] a = new long[1][2] return a").getClass());
assertEquals(float[][][].class, exec("float[][][] a = new float[1][2][3] return a").getClass());
assertEquals(double[][][][].class, exec("double[][][][] a = new double[1][2][3][4] return a").getClass());
assertEquals(boolean[][][][][].class, exec("boolean[][][][][] a = new boolean[1][2][3][4][5] return a").getClass());
assertEquals(String[][].class, exec("String[][] a = new String[1][2] return a").getClass());
assertEquals(Map[][][].class, exec("Map<String,Object>[][][] a = new Map<String,Object>[1][2][3] return a").getClass());
}
public void testContinueStatement() {
assertEquals(9, exec("int x = 0, y = 0 while (x < 10) { ++x if (x == 1) continue ++y } return y"));
}
public void testBreakStatement() {
assertEquals(4, exec("int x = 0, y = 0 while (x < 10) { ++x if (x == 5) break ++y } return y"));
}
public void testReturnStatement() {
assertEquals(10, exec("return 10"));
assertEquals(5, exec("int x = 5 return x"));
assertEquals(4, exec("int[] x = new int[2] x[1] = 4 return x[1]"));
assertEquals(5, ((short[])exec("short[] s = new short[3] s[1] = 5 return s"))[1]);
assertEquals(10, ((Map)exec("Map<String,Object> s = new HashMap< String,Object>() s.put(\"x\", 10) return s")).get("x"));
}
}

View File

@ -0,0 +1,48 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/** Tests for or operator across all types */
public class OrTests extends ScriptTestCase {
public void testInt() throws Exception {
assertEquals(5 | 12, exec("int x = 5; int y = 12; return x | y;"));
assertEquals(5 | -12, exec("int x = 5; int y = -12; return x | y;"));
assertEquals(7 | 15 | 3, exec("int x = 7; int y = 15; int z = 3; return x | y | z;"));
}
public void testIntConst() throws Exception {
assertEquals(5 | 12, exec("return 5 | 12;"));
assertEquals(5 | -12, exec("return 5 | -12;"));
assertEquals(7 | 15 | 3, exec("return 7 | 15 | 3;"));
}
public void testLong() throws Exception {
assertEquals(5L | 12L, exec("long x = 5; long y = 12; return x | y;"));
assertEquals(5L | -12L, exec("long x = 5; long y = -12; return x | y;"));
assertEquals(7L | 15L | 3L, exec("long x = 7; long y = 15; long z = 3; return x | y | z;"));
}
public void testLongConst() throws Exception {
assertEquals(5L | 12L, exec("return 5L | 12L;"));
assertEquals(5L | -12L, exec("return 5L | -12L;"));
assertEquals(7L | 15L | 3L, exec("return 7L | 15L | 3L;"));
}
}

View File

@ -0,0 +1,49 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
/** Runs yaml rest tests */
public class PlanARestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(PlanAPlugin.class);
}
public PlanARestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}
@ParametersFactory
public static Iterable<Object[]> parameters() throws IOException, RestTestParseException {
return ESRestTestCase.createParameters(0, 1);
}
}

View File

@ -0,0 +1,147 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/** Tests for division operator across all types */
//TODO: NaN/Inf/overflow/...
public class RemainderTests extends ScriptTestCase {
// TODO: byte,short,char
public void testInt() throws Exception {
assertEquals(1%1, exec("int x = 1; int y = 1; return x%y;"));
assertEquals(2%3, exec("int x = 2; int y = 3; return x%y;"));
assertEquals(5%10, exec("int x = 5; int y = 10; return x%y;"));
assertEquals(10%1%2, exec("int x = 10; int y = 1; int z = 2; return x%y%z;"));
assertEquals((10%1)%2, exec("int x = 10; int y = 1; int z = 2; return (x%y)%z;"));
assertEquals(10%(4%3), exec("int x = 10; int y = 4; int z = 3; return x%(y%z);"));
assertEquals(10%1, exec("int x = 10; int y = 1; return x%y;"));
assertEquals(0%1, exec("int x = 0; int y = 1; return x%y;"));
}
public void testIntConst() throws Exception {
assertEquals(1%1, exec("return 1%1;"));
assertEquals(2%3, exec("return 2%3;"));
assertEquals(5%10, exec("return 5%10;"));
assertEquals(10%1%2, exec("return 10%1%2;"));
assertEquals((10%1)%2, exec("return (10%1)%2;"));
assertEquals(10%(4%3), exec("return 10%(4%3);"));
assertEquals(10%1, exec("return 10%1;"));
assertEquals(0%1, exec("return 0%1;"));
}
public void testLong() throws Exception {
assertEquals(1L%1L, exec("long x = 1; long y = 1; return x%y;"));
assertEquals(2L%3L, exec("long x = 2; long y = 3; return x%y;"));
assertEquals(5L%10L, exec("long x = 5; long y = 10; return x%y;"));
assertEquals(10L%1L%2L, exec("long x = 10; long y = 1; long z = 2; return x%y%z;"));
assertEquals((10L%1L)%2L, exec("long x = 10; long y = 1; long z = 2; return (x%y)%z;"));
assertEquals(10L%(4L%3L), exec("long x = 10; long y = 4; long z = 3; return x%(y%z);"));
assertEquals(10L%1L, exec("long x = 10; long y = 1; return x%y;"));
assertEquals(0L%1L, exec("long x = 0; long y = 1; return x%y;"));
}
public void testLongConst() throws Exception {
assertEquals(1L%1L, exec("return 1L%1L;"));
assertEquals(2L%3L, exec("return 2L%3L;"));
assertEquals(5L%10L, exec("return 5L%10L;"));
assertEquals(10L%1L%2L, exec("return 10L%1L%2L;"));
assertEquals((10L%1L)%2L, exec("return (10L%1L)%2L;"));
assertEquals(10L%(4L%3L), exec("return 10L%(4L%3L);"));
assertEquals(10L%1L, exec("return 10L%1L;"));
assertEquals(0L%1L, exec("return 0L%1L;"));
}
public void testFloat() throws Exception {
assertEquals(1F%1F, exec("float x = 1; float y = 1; return x%y;"));
assertEquals(2F%3F, exec("float x = 2; float y = 3; return x%y;"));
assertEquals(5F%10F, exec("float x = 5; float y = 10; return x%y;"));
assertEquals(10F%1F%2F, exec("float x = 10; float y = 1; float z = 2; return x%y%z;"));
assertEquals((10F%1F)%2F, exec("float x = 10; float y = 1; float z = 2; return (x%y)%z;"));
assertEquals(10F%(4F%3F), exec("float x = 10; float y = 4; float z = 3; return x%(y%z);"));
assertEquals(10F%1F, exec("float x = 10; float y = 1; return x%y;"));
assertEquals(0F%1F, exec("float x = 0; float y = 1; return x%y;"));
}
public void testFloatConst() throws Exception {
assertEquals(1F%1F, exec("return 1F%1F;"));
assertEquals(2F%3F, exec("return 2F%3F;"));
assertEquals(5F%10F, exec("return 5F%10F;"));
assertEquals(10F%1F%2F, exec("return 10F%1F%2F;"));
assertEquals((10F%1F)%2F, exec("return (10F%1F)%2F;"));
assertEquals(10F%(4F%3F), exec("return 10F%(4F%3F);"));
assertEquals(10F%1F, exec("return 10F%1F;"));
assertEquals(0F%1F, exec("return 0F%1F;"));
}
public void testDouble() throws Exception {
assertEquals(1.0%1.0, exec("double x = 1; double y = 1; return x%y;"));
assertEquals(2.0%3.0, exec("double x = 2; double y = 3; return x%y;"));
assertEquals(5.0%10.0, exec("double x = 5; double y = 10; return x%y;"));
assertEquals(10.0%1.0%2.0, exec("double x = 10; double y = 1; double z = 2; return x%y%z;"));
assertEquals((10.0%1.0)%2.0, exec("double x = 10; double y = 1; double z = 2; return (x%y)%z;"));
assertEquals(10.0%(4.0%3.0), exec("double x = 10; double y = 4; double z = 3; return x%(y%z);"));
assertEquals(10.0%1.0, exec("double x = 10; double y = 1; return x%y;"));
assertEquals(0.0%1.0, exec("double x = 0; double y = 1; return x%y;"));
}
public void testDoubleConst() throws Exception {
assertEquals(1.0%1.0, exec("return 1.0%1.0;"));
assertEquals(2.0%3.0, exec("return 2.0%3.0;"));
assertEquals(5.0%10.0, exec("return 5.0%10.0;"));
assertEquals(10.0%1.0%2.0, exec("return 10.0%1.0%2.0;"));
assertEquals((10.0%1.0)%2.0, exec("return (10.0%1.0)%2.0;"));
assertEquals(10.0%(4.0%3.0), exec("return 10.0%(4.0%3.0);"));
assertEquals(10.0%1.0, exec("return 10.0%1.0;"));
assertEquals(0.0%1.0, exec("return 0.0%1.0;"));
}
public void testDivideByZero() throws Exception {
try {
exec("int x = 1; int y = 0; return x % y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {
// divide by zero
}
try {
exec("long x = 1L; long y = 0L; return x % y;");
fail("should have hit exception");
} catch (ArithmeticException expected) {
// divide by zero
}
}
public void testDivideByZeroConst() throws Exception {
try {
exec("return 1%0;");
fail("should have hit exception");
} catch (ArithmeticException expected) {
// divide by zero
}
try {
exec("return 1L%0L;");
fail("should have hit exception");
} catch (ArithmeticException expected) {
// divide by zero
}
}
}

View File

@ -0,0 +1,109 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.ScriptService;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class ScriptEngineTests extends ScriptTestCase {
public void testSimpleEquation() {
final Object value = exec("return 1 + 2;");
assertEquals(3, ((Number)value).intValue());
}
public void testMapAccess() {
Map<String, Object> vars = new HashMap<>();
Map<String, Object> obj2 = new HashMap<>();
obj2.put("prop2", "value2");
Map<String, Object> obj1 = new HashMap<>();
obj1.put("prop1", "value1");
obj1.put("obj2", obj2);
obj1.put("l", Arrays.asList("2", "1"));
vars.put("obj1", obj1);
Object value = exec("return input.get(\"obj1\");", vars);
obj1 = (Map<String, Object>)value;
assertEquals("value1", obj1.get("prop1"));
assertEquals("value2", ((Map<String, Object>) obj1.get("obj2")).get("prop2"));
value = exec("return ((List)((Map<String, Object>)input.get(\"obj1\")).get(\"l\")).get(0);", vars);
assertEquals("2", value);
}
public void testAccessListInScript() {
Map<String, Object> vars = new HashMap<>();
Map<String, Object> obj2 = new HashMap<>();
obj2.put("prop2", "value2");
Map<String, Object> obj1 = new HashMap<>();
obj1.put("prop1", "value1");
obj1.put("obj2", obj2);
vars.put("l", Arrays.asList("1", "2", "3", obj1));
assertEquals(4, exec("return ((List)input.get(\"l\")).size();", vars));
assertEquals("1", exec("return ((List)input.get(\"l\")).get(0);", vars));
Object value = exec("return ((List)input.get(\"l\")).get(3);", vars);
obj1 = (Map<String, Object>)value;
assertEquals("value1", obj1.get("prop1"));
assertEquals("value2", ((Map<String, Object>)obj1.get("obj2")).get("prop2"));
assertEquals("value1", exec("return ((Map<String, Object>)((List)input.get(\"l\")).get(3)).get(\"prop1\");", vars));
}
public void testChangingVarsCrossExecution1() {
Map<String, Object> vars = new HashMap<>();
Map<String, Object> ctx = new HashMap<>();
vars.put("ctx", ctx);
Object compiledScript = scriptEngine.compile("return ((Map<String, Object>)input.get(\"ctx\")).get(\"value\");");
ExecutableScript script = scriptEngine.executable(new CompiledScript(ScriptService.ScriptType.INLINE,
"testChangingVarsCrossExecution1", "plan-a", compiledScript), vars);
ctx.put("value", 1);
Object o = script.run();
assertEquals(1, ((Number) o).intValue());
ctx.put("value", 2);
o = script.run();
assertEquals(2, ((Number) o).intValue());
}
public void testChangingVarsCrossExecution2() {
Map<String, Object> vars = new HashMap<>();
Object compiledScript = scriptEngine.compile("return input.get(\"value\");");
ExecutableScript script = scriptEngine.executable(new CompiledScript(ScriptService.ScriptType.INLINE,
"testChangingVarsCrossExecution2", "plan-a", compiledScript), vars);
script.setNextVar("value", 1);
Object value = script.run();
assertEquals(1, ((Number)value).intValue());
script.setNextVar("value", 2);
value = script.run();
assertEquals(2, ((Number)value).intValue());
}
}

View File

@ -0,0 +1,61 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.test.ESTestCase;
import org.junit.Before;
import java.util.Map;
/**
* Base test case for scripting unit tests.
* <p>
* Typically just asserts the output of {@code exec()}
*/
public abstract class ScriptTestCase extends ESTestCase {
protected PlanAScriptEngineService scriptEngine;
/** Override to provide different compiler settings */
protected Settings getSettings() {
Settings.Builder builder = Settings.builder();
builder.put(PlanAScriptEngineService.NUMERIC_OVERFLOW, random().nextBoolean());
return builder.build();
}
@Before
public void setup() {
scriptEngine = new PlanAScriptEngineService(getSettings());
}
/** Compiles and returns the result of {@code script} */
public Object exec(String script) {
return exec(script, null);
}
/** Compiles and returns the result of {@code script} with access to {@code vars} */
public Object exec(String script, Map<String, Object> vars) {
Object object = scriptEngine.compile(script);
CompiledScript compiled = new CompiledScript(ScriptService.ScriptType.INLINE, getTestName(), "plan-a", object);
return scriptEngine.executable(compiled, vars).run();
}
}

View File

@ -0,0 +1,75 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
public class StringTests extends ScriptTestCase {
public void testAppend() {
// boolean
assertEquals("cat" + true, exec("String s = \"cat\"; return s + true;"));
// byte
assertEquals("cat" + (byte)3, exec("String s = \"cat\"; return s + (byte)3;"));
// short
assertEquals("cat" + (short)3, exec("String s = \"cat\"; return s + (short)3;"));
// char
assertEquals("cat" + 't', exec("String s = \"cat\"; return s + 't';"));
assertEquals("cat" + (char)40, exec("String s = \"cat\"; return s + (char)40;"));
// int
assertEquals("cat" + 2, exec("String s = \"cat\"; return s + 2;"));
// long
assertEquals("cat" + 2L, exec("String s = \"cat\"; return s + 2L;"));
// float
assertEquals("cat" + 2F, exec("String s = \"cat\"; return s + 2F;"));
// double
assertEquals("cat" + 2.0, exec("String s = \"cat\"; return s + 2.0;"));
// String
assertEquals("cat" + "cat", exec("String s = \"cat\"; return s + s;"));
}
public void testStringAPI() {
assertEquals("", exec("return new String();"));
assertEquals('x', exec("String s = \"x\"; return s.charAt(0);"));
assertEquals(120, exec("String s = \"x\"; return s.codePointAt(0);"));
assertEquals(0, exec("String s = \"x\"; return s.compareTo(\"x\");"));
assertEquals("xx", exec("String s = \"x\"; return s.concat(\"x\");"));
assertEquals(true, exec("String s = \"xy\"; return s.endsWith(\"y\");"));
assertEquals(2, exec("String t = \"abcde\"; return t.indexOf(\"cd\", 1);"));
assertEquals(false, exec("String t = \"abcde\"; return t.isEmpty();"));
assertEquals(5, exec("String t = \"abcde\"; return t.length();"));
assertEquals("cdcde", exec("String t = \"abcde\"; return t.replace(\"ab\", \"cd\");"));
assertEquals(false, exec("String s = \"xy\"; return s.startsWith(\"y\");"));
assertEquals("e", exec("String t = \"abcde\"; return t.substring(4, 5);"));
assertEquals(97, ((char[])exec("String s = \"a\"; return s.toCharArray();"))[0]);
assertEquals("a", exec("String s = \" a \"; return s.trim();"));
assertEquals('x', exec("return \"x\".charAt(0);"));
assertEquals(120, exec("return \"x\".codePointAt(0);"));
assertEquals(0, exec("return \"x\".compareTo(\"x\");"));
assertEquals("xx", exec("return \"x\".concat(\"x\");"));
assertEquals(true, exec("return \"xy\".endsWith(\"y\");"));
assertEquals(2, exec("return \"abcde\".indexOf(\"cd\", 1);"));
assertEquals(false, exec("return \"abcde\".isEmpty();"));
assertEquals(5, exec("return \"abcde\".length();"));
assertEquals("cdcde", exec("return \"abcde\".replace(\"ab\", \"cd\");"));
assertEquals(false, exec("return \"xy\".startsWith(\"y\");"));
assertEquals("e", exec("return \"abcde\".substring(4, 5);"));
assertEquals(97, ((char[])exec("return \"a\".toCharArray();"))[0]);
assertEquals("a", exec("return \" a \".trim();"));
}
}

View File

@ -0,0 +1,179 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/** Tests for subtraction operator across all types */
//TODO: NaN/Inf/overflow/...
public class SubtractionTests extends ScriptTestCase {
public void testInt() throws Exception {
assertEquals(1-1, exec("int x = 1; int y = 1; return x-y;"));
assertEquals(2-3, exec("int x = 2; int y = 3; return x-y;"));
assertEquals(5-10, exec("int x = 5; int y = 10; return x-y;"));
assertEquals(1-1-2, exec("int x = 1; int y = 1; int z = 2; return x-y-z;"));
assertEquals((1-1)-2, exec("int x = 1; int y = 1; int z = 2; return (x-y)-z;"));
assertEquals(1-(1-2), exec("int x = 1; int y = 1; int z = 2; return x-(y-z);"));
assertEquals(10-0, exec("int x = 10; int y = 0; return x-y;"));
assertEquals(0-0, exec("int x = 0; int y = 0; return x-x;"));
}
public void testIntConst() throws Exception {
assertEquals(1-1, exec("return 1-1;"));
assertEquals(2-3, exec("return 2-3;"));
assertEquals(5-10, exec("return 5-10;"));
assertEquals(1-1-2, exec("return 1-1-2;"));
assertEquals((1-1)-2, exec("return (1-1)-2;"));
assertEquals(1-(1-2), exec("return 1-(1-2);"));
assertEquals(10-0, exec("return 10-0;"));
assertEquals(0-0, exec("return 0-0;"));
}
public void testByte() throws Exception {
assertEquals((byte)1-(byte)1, exec("byte x = 1; byte y = 1; return x-y;"));
assertEquals((byte)2-(byte)3, exec("byte x = 2; byte y = 3; return x-y;"));
assertEquals((byte)5-(byte)10, exec("byte x = 5; byte y = 10; return x-y;"));
assertEquals((byte)1-(byte)1-(byte)2, exec("byte x = 1; byte y = 1; byte z = 2; return x-y-z;"));
assertEquals(((byte)1-(byte)1)-(byte)2, exec("byte x = 1; byte y = 1; byte z = 2; return (x-y)-z;"));
assertEquals((byte)1-((byte)1-(byte)2), exec("byte x = 1; byte y = 1; byte z = 2; return x-(y-z);"));
assertEquals((byte)10-(byte)1, exec("byte x = 10; byte y = 1; return x-y;"));
assertEquals((byte)0-(byte)0, exec("byte x = 0; byte y = 0; return x-y;"));
}
public void testByteConst() throws Exception {
assertEquals((byte)1-(byte)1, exec("return (byte)1-(byte)1;"));
assertEquals((byte)2-(byte)3, exec("return (byte)2-(byte)3;"));
assertEquals((byte)5-(byte)10, exec("return (byte)5-(byte)10;"));
assertEquals((byte)1-(byte)1-(byte)2, exec("return (byte)1-(byte)1-(byte)2;"));
assertEquals(((byte)1-(byte)1)-(byte)2, exec("return ((byte)1-(byte)1)-(byte)2;"));
assertEquals((byte)1-((byte)1-(byte)2), exec("return (byte)1-((byte)1-(byte)2);"));
assertEquals((byte)10-(byte)1, exec("return (byte)10-(byte)1;"));
assertEquals((byte)0-(byte)0, exec("return (byte)0-(byte)0;"));
}
public void testChar() throws Exception {
assertEquals((char)1-(char)1, exec("char x = 1; char y = 1; return x-y;"));
assertEquals((char)2-(char)3, exec("char x = 2; char y = 3; return x-y;"));
assertEquals((char)5-(char)10, exec("char x = 5; char y = 10; return x-y;"));
assertEquals((char)1-(char)1-(char)2, exec("char x = 1; char y = 1; char z = 2; return x-y-z;"));
assertEquals(((char)1-(char)1)-(char)2, exec("char x = 1; char y = 1; char z = 2; return (x-y)-z;"));
assertEquals((char)1-((char)1-(char)2), exec("char x = 1; char y = 1; char z = 2; return x-(y-z);"));
assertEquals((char)10-(char)1, exec("char x = 10; char y = 1; return x-y;"));
assertEquals((char)0-(char)0, exec("char x = 0; char y = 0; return x-y;"));
}
public void testCharConst() throws Exception {
assertEquals((char)1-(char)1, exec("return (char)1-(char)1;"));
assertEquals((char)2-(char)3, exec("return (char)2-(char)3;"));
assertEquals((char)5-(char)10, exec("return (char)5-(char)10;"));
assertEquals((char)1-(char)1-(char)2, exec("return (char)1-(char)1-(char)2;"));
assertEquals(((char)1-(char)1)-(char)2, exec("return ((char)1-(char)1)-(char)2;"));
assertEquals((char)1-((char)1-(char)2), exec("return (char)1-((char)1-(char)2);"));
assertEquals((char)10-(char)1, exec("return (char)10-(char)1;"));
assertEquals((char)0-(char)0, exec("return (char)0-(char)0;"));
}
public void testShort() throws Exception {
assertEquals((short)1-(short)1, exec("short x = 1; short y = 1; return x-y;"));
assertEquals((short)2-(short)3, exec("short x = 2; short y = 3; return x-y;"));
assertEquals((short)5-(short)10, exec("short x = 5; short y = 10; return x-y;"));
assertEquals((short)1-(short)1-(short)2, exec("short x = 1; short y = 1; short z = 2; return x-y-z;"));
assertEquals(((short)1-(short)1)-(short)2, exec("short x = 1; short y = 1; short z = 2; return (x-y)-z;"));
assertEquals((short)1-((short)1-(short)2), exec("short x = 1; short y = 1; short z = 2; return x-(y-z);"));
assertEquals((short)10-(short)1, exec("short x = 10; short y = 1; return x-y;"));
assertEquals((short)0-(short)0, exec("short x = 0; short y = 0; return x-y;"));
}
public void testShortConst() throws Exception {
assertEquals((short)1-(short)1, exec("return (short)1-(short)1;"));
assertEquals((short)2-(short)3, exec("return (short)2-(short)3;"));
assertEquals((short)5-(short)10, exec("return (short)5-(short)10;"));
assertEquals((short)1-(short)1-(short)2, exec("return (short)1-(short)1-(short)2;"));
assertEquals(((short)1-(short)1)-(short)2, exec("return ((short)1-(short)1)-(short)2;"));
assertEquals((short)1-((short)1-(short)2), exec("return (short)1-((short)1-(short)2);"));
assertEquals((short)10-(short)1, exec("return (short)10-(short)1;"));
assertEquals((short)0-(short)0, exec("return (short)0-(short)0;"));
}
public void testLong() throws Exception {
assertEquals(1L-1L, exec("long x = 1; long y = 1; return x-y;"));
assertEquals(2L-3L, exec("long x = 2; long y = 3; return x-y;"));
assertEquals(5L-10L, exec("long x = 5; long y = 10; return x-y;"));
assertEquals(1L-1L-2L, exec("long x = 1; long y = 1; int z = 2; return x-y-z;"));
assertEquals((1L-1L)-2L, exec("long x = 1; long y = 1; int z = 2; return (x-y)-z;"));
assertEquals(1L-(1L-2L), exec("long x = 1; long y = 1; int z = 2; return x-(y-z);"));
assertEquals(10L-0L, exec("long x = 10; long y = 0; return x-y;"));
assertEquals(0L-0L, exec("long x = 0; long y = 0; return x-x;"));
}
public void testLongConst() throws Exception {
assertEquals(1L-1L, exec("return 1L-1L;"));
assertEquals(2L-3L, exec("return 2L-3L;"));
assertEquals(5L-10L, exec("return 5L-10L;"));
assertEquals(1L-1L-2L, exec("return 1L-1L-2L;"));
assertEquals((1L-1L)-2L, exec("return (1L-1L)-2L;"));
assertEquals(1L-(1L-2L), exec("return 1L-(1L-2L);"));
assertEquals(10L-0L, exec("return 10L-0L;"));
assertEquals(0L-0L, exec("return 0L-0L;"));
}
public void testFloat() throws Exception {
assertEquals(1F-1F, exec("float x = 1; float y = 1; return x-y;"));
assertEquals(2F-3F, exec("float x = 2; float y = 3; return x-y;"));
assertEquals(5F-10F, exec("float x = 5; float y = 10; return x-y;"));
assertEquals(1F-1F-2F, exec("float x = 1; float y = 1; float z = 2; return x-y-z;"));
assertEquals((1F-1F)-2F, exec("float x = 1; float y = 1; float z = 2; return (x-y)-z;"));
assertEquals(1F-(1F-2F), exec("float x = 1; float y = 1; float z = 2; return x-(y-z);"));
assertEquals(10F-0F, exec("float x = 10; float y = 0; return x-y;"));
assertEquals(0F-0F, exec("float x = 0; float y = 0; return x-x;"));
}
public void testFloatConst() throws Exception {
assertEquals(1F-1F, exec("return 1F-1F;"));
assertEquals(2F-3F, exec("return 2F-3F;"));
assertEquals(5F-10F, exec("return 5F-10F;"));
assertEquals(1F-1F-2F, exec("return 1F-1F-2F;"));
assertEquals((1F-1F)-2F, exec("return (1F-1F)-2F;"));
assertEquals(1F-(1F-2F), exec("return 1F-(1F-2F);"));
assertEquals(10F-0F, exec("return 10F-0F;"));
assertEquals(0F-0F, exec("return 0F-0F;"));
}
public void testDouble() throws Exception {
assertEquals(1D-1D, exec("double x = 1; double y = 1; return x-y;"));
assertEquals(2D-3D, exec("double x = 2; double y = 3; return x-y;"));
assertEquals(5D-10D, exec("double x = 5; double y = 10; return x-y;"));
assertEquals(1D-1D-2D, exec("double x = 1; double y = 1; double z = 2; return x-y-z;"));
assertEquals((1D-1D)-2D, exec("double x = 1; double y = 1; double z = 2; return (x-y)-z;"));
assertEquals(1D-(1D-2D), exec("double x = 1; double y = 1; double z = 2; return x-(y-z);"));
assertEquals(10D-0D, exec("double x = 10; float y = 0; return x-y;"));
assertEquals(0D-0D, exec("double x = 0; float y = 0; return x-x;"));
}
public void testyDoubleConst() throws Exception {
assertEquals(1.0-1.0, exec("return 1.0-1.0;"));
assertEquals(2.0-3.0, exec("return 2.0-3.0;"));
assertEquals(5.0-10.0, exec("return 5.0-10.0;"));
assertEquals(1.0-1.0-2.0, exec("return 1.0-1.0-2.0;"));
assertEquals((1.0-1.0)-2.0, exec("return (1.0-1.0)-2.0;"));
assertEquals(1.0-(1.0-2.0), exec("return 1.0-(1.0-2.0);"));
assertEquals(10.0-0.0, exec("return 10.0-0.0;"));
assertEquals(0.0-0.0, exec("return 0.0-0.0;"));
}
}

View File

@ -0,0 +1,42 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/** Tests for unary operators across different types */
public class UnaryTests extends ScriptTestCase {
/** basic tests */
public void testBasics() {
assertEquals(false, exec("return !true;"));
assertEquals(true, exec("boolean x = false; return !x;"));
assertEquals(-2, exec("return ~1;"));
assertEquals(-2, exec("byte x = 1; return ~x;"));
assertEquals(1, exec("return +1;"));
assertEquals(1.0, exec("double x = 1; return +x;"));
assertEquals(-1, exec("return -1;"));
assertEquals(-2, exec("short x = 2; return -x;"));
}
public void testNegationInt() throws Exception {
assertEquals(-1, exec("return -1;"));
assertEquals(1, exec("return -(-1);"));
assertEquals(0, exec("return -0;"));
}
}

View File

@ -0,0 +1,250 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
import org.elasticsearch.test.ESTestCase;
/**
* Tests utility methods (typically built-ins)
*/
public class UtilityTests extends ESTestCase {
public void testDivideWithoutOverflowInt() {
assertEquals(5 / 2, Utility.divideWithoutOverflow(5, 2));
try {
Utility.divideWithoutOverflow(Integer.MIN_VALUE, -1);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.divideWithoutOverflow(5, 0);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testDivideWithoutOverflowLong() {
assertEquals(5L / 2L, Utility.divideWithoutOverflow(5L, 2L));
try {
Utility.divideWithoutOverflow(Long.MIN_VALUE, -1L);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.divideWithoutOverflow(5L, 0L);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testToByteExact() {
for (int b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
assertEquals((byte)b, Utility.toByteExact(b));
}
try {
Utility.toByteExact(Byte.MIN_VALUE - 1);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.toByteExact(Byte.MAX_VALUE + 1);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testToShortExact() {
for (int s = Short.MIN_VALUE; s < Short.MAX_VALUE; s++) {
assertEquals((short)s, Utility.toShortExact(s));
}
try {
Utility.toShortExact(Short.MIN_VALUE - 1);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.toShortExact(Short.MAX_VALUE + 1);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testToCharExact() {
for (int c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) {
assertEquals((char)c, Utility.toCharExact(c));
}
try {
Utility.toCharExact(Character.MIN_VALUE - 1);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.toCharExact(Character.MAX_VALUE + 1);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testAddWithoutOverflowFloat() {
assertEquals(10F, Utility.addWithoutOverflow(5F, 5F), 0F);
assertTrue(Float.isNaN(Utility.addWithoutOverflow(5F, Float.NaN)));
assertTrue(Float.isNaN(Utility.addWithoutOverflow(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY)));
try {
Utility.addWithoutOverflow(Float.MAX_VALUE, Float.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.addWithoutOverflow(-Float.MAX_VALUE, -Float.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testAddWithoutOverflowDouble() {
assertEquals(10D, Utility.addWithoutOverflow(5D, 5D), 0D);
assertTrue(Double.isNaN(Utility.addWithoutOverflow(5D, Double.NaN)));
assertTrue(Double.isNaN(Utility.addWithoutOverflow(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)));
try {
Utility.addWithoutOverflow(Double.MAX_VALUE, Double.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.addWithoutOverflow(-Double.MAX_VALUE, -Double.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testSubtractWithoutOverflowFloat() {
assertEquals(5F, Utility.subtractWithoutOverflow(10F, 5F), 0F);
assertTrue(Float.isNaN(Utility.subtractWithoutOverflow(5F, Float.NaN)));
assertTrue(Float.isNaN(Utility.subtractWithoutOverflow(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)));
try {
Utility.subtractWithoutOverflow(Float.MAX_VALUE, -Float.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.subtractWithoutOverflow(-Float.MAX_VALUE, Float.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testSubtractWithoutOverflowDouble() {
assertEquals(5D, Utility.subtractWithoutOverflow(10D, 5D), 0D);
assertTrue(Double.isNaN(Utility.subtractWithoutOverflow(5D, Double.NaN)));
assertTrue(Double.isNaN(Utility.subtractWithoutOverflow(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)));
try {
Utility.subtractWithoutOverflow(Double.MAX_VALUE, -Double.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.subtractWithoutOverflow(-Double.MAX_VALUE, Double.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testMultiplyWithoutOverflowFloat() {
assertEquals(25F, Utility.multiplyWithoutOverflow(5F, 5F), 0F);
assertTrue(Float.isNaN(Utility.multiplyWithoutOverflow(5F, Float.NaN)));
assertEquals(Float.POSITIVE_INFINITY, Utility.multiplyWithoutOverflow(5F, Float.POSITIVE_INFINITY), 0F);
try {
Utility.multiplyWithoutOverflow(Float.MAX_VALUE, Float.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testMultiplyWithoutOverflowDouble() {
assertEquals(25D, Utility.multiplyWithoutOverflow(5D, 5D), 0D);
assertTrue(Double.isNaN(Utility.multiplyWithoutOverflow(5D, Double.NaN)));
assertEquals(Double.POSITIVE_INFINITY, Utility.multiplyWithoutOverflow(5D, Double.POSITIVE_INFINITY), 0D);
try {
Utility.multiplyWithoutOverflow(Double.MAX_VALUE, Double.MAX_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testDivideWithoutOverflowFloat() {
assertEquals(5F, Utility.divideWithoutOverflow(25F, 5F), 0F);
assertTrue(Float.isNaN(Utility.divideWithoutOverflow(5F, Float.NaN)));
assertEquals(Float.POSITIVE_INFINITY, Utility.divideWithoutOverflow(Float.POSITIVE_INFINITY, 5F), 0F);
try {
Utility.divideWithoutOverflow(Float.MAX_VALUE, Float.MIN_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.divideWithoutOverflow(0F, 0F);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.divideWithoutOverflow(5F, 0F);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testDivideWithoutOverflowDouble() {
assertEquals(5D, Utility.divideWithoutOverflow(25D, 5D), 0D);
assertTrue(Double.isNaN(Utility.divideWithoutOverflow(5D, Double.NaN)));
assertEquals(Double.POSITIVE_INFINITY, Utility.divideWithoutOverflow(Double.POSITIVE_INFINITY, 5D), 0D);
try {
Utility.divideWithoutOverflow(Double.MAX_VALUE, Double.MIN_VALUE);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.divideWithoutOverflow(0D, 0D);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
try {
Utility.divideWithoutOverflow(5D, 0D);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testRemainderWithoutOverflowFloat() {
assertEquals(1F, Utility.remainderWithoutOverflow(25F, 4F), 0F);
try {
Utility.remainderWithoutOverflow(5F, 0F);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
public void testRemainderWithoutOverflowDouble() {
assertEquals(1D, Utility.remainderWithoutOverflow(25D, 4D), 0D);
try {
Utility.remainderWithoutOverflow(5D, 0D);
fail("did not get expected exception");
} catch (ArithmeticException expected) {}
}
}

View File

@ -0,0 +1,41 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
public class WhenThingsGoWrongTests extends ScriptTestCase {
public void testNullPointer() {
try {
exec("int x = (int) ((Map) input).get(\"missing\"); return x;");
fail("should have hit npe");
} catch (NullPointerException expected) {}
}
public void testInvalidShift() {
try {
exec("float x = 15F; x <<= 2; return x;");
fail("should have hit cce");
} catch (ClassCastException expected) {}
try {
exec("double x = 15F; x <<= 2; return x;");
fail("should have hit cce");
} catch (ClassCastException expected) {}
}
}

View File

@ -0,0 +1,62 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.plan.a;
/** Tests for xor operator across all types */
public class XorTests extends ScriptTestCase {
public void testInt() throws Exception {
assertEquals(5 ^ 12, exec("int x = 5; int y = 12; return x ^ y;"));
assertEquals(5 ^ -12, exec("int x = 5; int y = -12; return x ^ y;"));
assertEquals(7 ^ 15 ^ 3, exec("int x = 7; int y = 15; int z = 3; return x ^ y ^ z;"));
}
public void testIntConst() throws Exception {
assertEquals(5 ^ 12, exec("return 5 ^ 12;"));
assertEquals(5 ^ -12, exec("return 5 ^ -12;"));
assertEquals(7 ^ 15 ^ 3, exec("return 7 ^ 15 ^ 3;"));
}
public void testLong() throws Exception {
assertEquals(5L ^ 12L, exec("long x = 5; long y = 12; return x ^ y;"));
assertEquals(5L ^ -12L, exec("long x = 5; long y = -12; return x ^ y;"));
assertEquals(7L ^ 15L ^ 3L, exec("long x = 7; long y = 15; long z = 3; return x ^ y ^ z;"));
}
public void testLongConst() throws Exception {
assertEquals(5L ^ 12L, exec("return 5L ^ 12L;"));
assertEquals(5L ^ -12L, exec("return 5L ^ -12L;"));
assertEquals(7L ^ 15L ^ 3L, exec("return 7L ^ 15L ^ 3L;"));
}
public void testBool() throws Exception {
assertEquals(false, exec("boolean x = true; boolean y = true; return x ^ y;"));
assertEquals(true, exec("boolean x = true; boolean y = false; return x ^ y;"));
assertEquals(true, exec("boolean x = false; boolean y = true; return x ^ y;"));
assertEquals(false, exec("boolean x = false; boolean y = false; return x ^ y;"));
}
public void testBoolConst() throws Exception {
assertEquals(false, exec("return true ^ true;"));
assertEquals(true, exec("return true ^ false;"));
assertEquals(true, exec("return false ^ true;"));
assertEquals(false, exec("return false ^ false;"));
}
}

View File

@ -0,0 +1,14 @@
# Integration tests for Plan A Plugin
#
"Plan A plugin loaded":
- do:
cluster.state: {}
# Get master node id
- set: { master_node: master }
- do:
nodes.info: {}
- match: { nodes.$master.plugins.0.name: lang-plan-a }
- match: { nodes.$master.plugins.0.jvm: true }

View File

@ -0,0 +1,27 @@
# Integration tests for using a scripted field
#
setup:
- do:
index:
index: test
type: test
id: 1
body: { "foo": "aaa" }
- do:
indices.refresh: {}
---
"Scripted Field":
- do:
search:
body:
script_fields:
bar:
script:
inline: "input.doc.foo.0 + input.x;"
lang: plan-a
params:
x: "bbb"
- match: { hits.hits.0.fields.bar.0: "aaabbb"}

View File

@ -0,0 +1,97 @@
# Integration tests for Plan-A search scripting
#
"Plan-A Query":
- do:
index:
index: test
type: test
id: 1
body: { "test": "value beck", "num1": 1.0 }
- do:
index:
index: test
type: test
id: 2
body: { "test": "value beck", "num1": 2.0 }
- do:
index:
index: test
type: test
id: 3
body: { "test": "value beck", "num1": 3.0 }
- do:
indices.refresh: {}
- do:
index: test
search:
body:
query:
script:
script:
inline: "input.doc.num1.0 > 1;"
lang: plan-a
script_fields:
sNum1:
script:
inline: "input.doc.num1.0;"
lang: plan-a
sort:
num1:
order: asc
- match: { hits.total: 2 }
- match: { hits.hits.0.fields.sNum1.0: 2.0 }
- match: { hits.hits.1.fields.sNum1.0: 3.0 }
- do:
index: test
search:
body:
query:
script:
script:
inline: "input.doc.num1.0 > input.param1;"
lang: plan-a
params:
param1: 1
script_fields:
sNum1:
script:
inline: "return input.doc.num1.0;"
lang: plan-a
sort:
num1:
order: asc
- match: { hits.total: 2 }
- match: { hits.hits.0.fields.sNum1.0: 2.0 }
- match: { hits.hits.1.fields.sNum1.0: 3.0 }
- do:
index: test
search:
body:
query:
script:
script:
inline: "input.doc.num1.0 > input.param1;"
lang: plan-a
params:
param1: -1
script_fields:
sNum1:
script:
inline: "input.doc.num1.0;"
lang: plan-a
sort:
num1:
order: asc
- match: { hits.total: 3 }
- match: { hits.hits.0.fields.sNum1.0: 1.0 }
- match: { hits.hits.1.fields.sNum1.0: 2.0 }
- match: { hits.hits.2.fields.sNum1.0: 3.0 }

View File

@ -631,6 +631,7 @@ public class PluginManagerTests extends ESIntegTestCase {
PluginManager.checkForOfficialPlugins("analysis-stempel");
PluginManager.checkForOfficialPlugins("delete-by-query");
PluginManager.checkForOfficialPlugins("lang-javascript");
PluginManager.checkForOfficialPlugins("lang-plan-a");
PluginManager.checkForOfficialPlugins("lang-python");
PluginManager.checkForOfficialPlugins("mapper-attachments");
PluginManager.checkForOfficialPlugins("mapper-murmur3");

View File

@ -223,6 +223,18 @@ fi
install_and_check_plugin discovery multicast
}
@test "[$GROUP] install lang-expression plugin" {
install_and_check_plugin lang expression
}
@test "[$GROUP] install lang-groovy plugin" {
install_and_check_plugin lang groovy
}
@test "[$GROUP] install lang-plan-a plugin" {
install_and_check_plugin lang plan-a
}
@test "[$GROUP] install javascript plugin" {
install_and_check_plugin lang javascript rhino-*.jar
}
@ -323,6 +335,18 @@ fi
remove_plugin discovery-multicast
}
@test "[$GROUP] remove lang-expression plugin" {
remove_plugin lang-expression
}
@test "[$GROUP] remove lang-groovy plugin" {
remove_plugin lang-groovy
}
@test "[$GROUP] remove lang-plan-a plugin" {
remove_plugin lang-plan-a
}
@test "[$GROUP] remove javascript plugin" {
remove_plugin lang-javascript
}

View File

@ -22,6 +22,7 @@ List projects = [
'plugins:discovery-gce',
'plugins:discovery-multicast',
'plugins:lang-javascript',
'plugins:lang-plan-a',
'plugins:lang-python',
'plugins:mapper-attachments',
'plugins:mapper-murmur3',