ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/el/parser/TestAstLambdaExpression.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/el/parser/TestAstLambdaExpression.java
Status
scanned
Type
file
Name
TestAstLambdaExpression.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
7564 (7.4 KB)
MD5
a3b500c9deb53fdac6573ca00200b689
SHA1
72e9756eac862ca590dea6da14efb28485dd0339
SHA256
472bd7e6944b3d24545ae03f32ae60ad282ab11470e9ffddd2ba66980da18f5e
SHA512

      
    
SHA1_git
c7aad38d34339cc2678f785e8ef60d747be6d3de
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestAstLambdaExpression.java | 7.4 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF 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.apache.el.parser; import jakarta.el.ELException; import jakarta.el.ELProcessor; import org.junit.Assert; import org.junit.Test; public class TestAstLambdaExpression { @Test public void testSpec01() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("(x->x+1)(1)", Integer.class); Assert.assertEquals(Integer.valueOf(2), result); } @Test public void testSpec02() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("((x,y)->x+y)(1,2)", Integer.class); Assert.assertEquals(Integer.valueOf(3), result); } @Test public void testSpec03() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("(()->64)", Integer.class); Assert.assertEquals(Integer.valueOf(64), result); } @Test public void testSpec04() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("v = (x,y)->x+y; v(3,4)", Integer.class); Assert.assertEquals(Integer.valueOf(7), result); } @Test public void testSpec05() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("fact = n -> n==0? 1: n*fact(n-1); fact(5)", Integer.class); Assert.assertEquals(Integer.valueOf(120), result); } @Test public void testSpec06() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("(x->y->x-y)(2)(1)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test public void testInvocation01() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("(()->2)()", Integer.class); Assert.assertEquals(Integer.valueOf(2), result); } @Test public void testNested01() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("(()->y->2-y)()(1)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test public void testNested02() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("(()->y->()->2-y)()(1)()", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test(expected=ELException.class) public void testNested03() { ELProcessor processor = new ELProcessor(); // More method parameters than there are nested lambda expressions processor.getValue("(()->y->()->2-y)()(1)()()", Integer.class); } @Test public void testNested04() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("(()->y->()->x->x-y)()(1)()(2)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test public void testNested05() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("(()->y->()->()->x->x-y)()(1)()()(2)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test public void testNested06() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("(()->y->()->()->x->x-y)()(1)()(3)(2)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test public void testNested07() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("()->()->()->42", Integer.class); Assert.assertEquals(Integer.valueOf(42), result); } @Test public void testLambdaAsFunction01() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("v = (x->y->x-y); v(2)(1)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test public void testLambdaAsFunction02() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("v = (()->y->2-y); v()(1)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test public void testLambdaAsFunction03() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("v = (()->y->()->2-y); v()(1)()", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test(expected=ELException.class) public void testLambdaAsFunction04() { ELProcessor processor = new ELProcessor(); // More method parameters than there are nested lambda expressions processor.getValue("v = (()->y->()->2-y); v()(1)()()", Integer.class); } @Test public void testLambdaAsFunction05() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("v = (()->y->()->x->x-y); v()(1)()(2)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test public void testLambdaAsFunction06() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("v = (()->y->()->()->x->x-y); v()(1)()()(2)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test public void testLambdaAsFunction07() { ELProcessor processor = new ELProcessor(); Object result = processor.getValue("v = (()->y->()->()->x->x-y); v()(1)()(3)(2)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } @Test(expected=ELException.class) public void testLambdaAsFunction08() { // Using a name space for the function is not allowed ELProcessor processor = new ELProcessor(); Object result = processor.getValue("foo:v = (x)->x+1; foo:v(0)", Integer.class); Assert.assertEquals(Integer.valueOf(1), result); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
16.98
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9