|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2022 JSQLParser |
| 6 | + * %% |
| 7 | + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 |
| 8 | + * #L% |
| 9 | + */ |
| 10 | +package net.sf.jsqlparser.expression; |
| 11 | + |
| 12 | +import net.sf.jsqlparser.JSQLParserException; |
| 13 | +import net.sf.jsqlparser.test.TestUtils; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | + |
| 16 | +/** |
| 17 | + * @author Mathieu Goeminne |
| 18 | + */ |
| 19 | +public class CaseExpressionTest { |
| 20 | + @Test |
| 21 | + public void testSimpleCase() throws JSQLParserException { |
| 22 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true THEN 1 ELSE 2 END", true); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testCaseBinaryAndWhen() throws JSQLParserException { |
| 27 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true & false THEN 1 ELSE 2 END", true); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testCaseBinaryOrWhen() throws JSQLParserException { |
| 32 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true | false THEN 1 ELSE 2 END", true); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testCaseExclamationWhen() throws JSQLParserException { |
| 37 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN !true THEN 1 ELSE 2 END", true); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testCaseNotWhen() throws JSQLParserException { |
| 42 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN NOT true THEN 1 ELSE 2 END", true); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testCaseAndWhen() throws JSQLParserException { |
| 47 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true AND false THEN 1 ELSE 2 END", true); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testCaseOrWhen() throws JSQLParserException { |
| 52 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true WHEN true OR false THEN 1 ELSE 2 END", true); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testCaseExclamationSwitch() throws JSQLParserException { |
| 57 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE !true WHEN true THEN 1 ELSE 2 END", true); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testCaseNotSwitch() throws JSQLParserException { |
| 62 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE NOT true WHEN true THEN 1 ELSE 2 END", true); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void testCaseBinaryAndSwitch() throws JSQLParserException { |
| 67 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true & false WHEN true THEN 1 ELSE 2 END", true); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + public void testCaseBinaryOrSwitch() throws JSQLParserException { |
| 72 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true | false WHEN true THEN 1 ELSE 2 END", true); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testCaseAndSwitch() throws JSQLParserException { |
| 77 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true AND false WHEN true THEN 1 ELSE 2 END", true); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testCaseOrSwitch() throws JSQLParserException { |
| 82 | + TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true OR false WHEN true THEN 1 ELSE 2 END", true); |
| 83 | + } |
| 84 | +} |
0 commit comments