package com.alibaba.druid.bvt.sql;

import com.alibaba.druid.sql.ast.expr.SQLCaseExpr;
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
import junit.framework.TestCase;

import static org.junit.Assert.assertNotEquals;

public class EqualTest_case extends TestCase {
    public void test_exits() throws Exception {
        String sql = "case x when 1 then 0 else 2 end";
        String sql_c = "case x when 2 then 0 else 2 end";
        SQLCaseExpr exprA, exprB, exprC;
        {
            OracleExprParser parser = new OracleExprParser(sql);
            exprA = (SQLCaseExpr) parser.expr();
        }
        {
            OracleExprParser parser = new OracleExprParser(sql);
            exprB = (SQLCaseExpr) parser.expr();
        }
        {
            OracleExprParser parser = new OracleExprParser(sql_c);
            exprC = (SQLCaseExpr) parser.expr();
        }
        assertEquals(exprA, exprB);
        assertNotEquals(exprA, exprC);
        assertTrue(exprA.equals(exprA));
        assertFalse(exprA.equals(new Object()));
        assertEquals(exprA.hashCode(), exprB.hashCode());

        assertEquals(new SQLCaseExpr(), new SQLCaseExpr());
        assertEquals(new SQLCaseExpr().hashCode(), new SQLCaseExpr().hashCode());
    }
}
