/*
 * 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.painless;

/** Tests for special reserved words such as _score */
public class ReservedWordTests extends ScriptTestCase {
    
    /** check that we can't declare a variable of _score, its really reserved! */
    public void testScoreVar() {
        IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
            exec("int _score = 5; return _score;");
        });
        assertTrue(expected.getMessage().contains("Variable name [_score] already defined"));
    }
    
    /** check that we can't write to _score, its read-only! */
    public void testScoreStore() {
        IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
            exec("_score = 5; return _score;");
        });
        assertTrue(expected.getMessage().contains("Variable [_score] is read-only"));
    }
}

@@ -1664,10 +1664,718 @@
 ;%0A    %7D%0A
+    %0A    /** check that we can't declare a variable of doc, its really reserved! */%0A    public void testDocVar() %7B%0A        IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -%3E %7B%0A            exec(%22int doc = 5; return doc;%22);%0A        %7D);%0A        assertTrue(expected.getMessage().contains(%22Variable name %5Bdoc%5D already defined%22));%0A    %7D%0A    %0A    /** check that we can't write to _score, its read-only! */%0A    public void testDocStore() %7B%0A        IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -%3E %7B%0A            exec(%22doc = 5; return doc;%22);%0A        %7D);%0A        assertTrue(expected.getMessage().contains(%22Variable %5Bdoc%5D is read-only%22));%0A    %7D%0A
 %7D%0A

add reserved word tests for 'doc', too