<commit_before>package ru.yandex.mysqlDiff.diff

import scalax.testing._
import ru.yandex.mysqlDiff.model._


object DiffTest extends TestSuite("Simple Diff") {
/*
    "Name Diff" is {
    
        val o1 = new SqlObjectType("o1")
        val o2 = new SqlObjectType("o2")
        val o1_eq = new SqlObjectType("o1")

        var i = 0
        NameDiffMaker.doDiff(o1, o1_eq, o => {
            fail("FAIL ME:" + o)
        })
        assert("Diff is runned", i == 0)
    
        NameDiffMaker.doDiff(o1, o2, o => {
            i = i + 1
            assert("First of diff is fail", o.from == o1)
            assert("First of diff is fail", o.to == o2)
           true
        })
    }

  
    "Column Diff" is {
    
        val c1: ColumnModel = new ColumnModel("c1", new DataType("int", None));
        val c1_eq: ColumnModel = new ColumnModel("c1", new DataType("int", None));


        val m: ColumnDiffMaker.AddDiffFunction = o => {
            fail("Fail with:" + o)
        }
        ColumnDiffMaker.doDiff(c1, c1_eq, m);
    
        val c2: ColumnModel = ColumnModel("c2", new DataType("varchar", Some(20)))

        var isNameFind = false;
        var isDataTypeFind = false;
        var i = 0;


        val m2: ColumnDiffMaker.AddDiffFunction = o => {
            if (o.isInstanceOf[NameDiff[SqlObjectType]]) isNameFind = true
            if (o.isInstanceOf[DataTypeDiff]) isDataTypeFind = true
            i = i + 1
            true
        }
        ColumnDiffMaker.doDiff(c1, c2, m2)
        assert("Diff count: " + i, i == 2)
        assert("Is name find", isNameFind)
        assert("Is type find", isDataTypeFind)
    }

    object SimpleListDiff extends NameDiffMaker with ListDiffMaker {

    }
  
  
    "List Diff" is {
        val c1: ColumnModel = new ColumnModel("c1", new DataType("varchar", Some(11)));
        val c1t: ColumnModel = new ColumnModel("c1", new DataType("int", Some(11)));
        val c2: ColumnModel = new ColumnModel("c2", new DataType("varchar", Some(11)));
        val c3: ColumnModel = new ColumnModel("c3", new DataType("int", Some(11)));
        val c4: ColumnModel = new ColumnModel("c4", new DataType("int", Some(11)));

        val s1 = List[ColumnModel](c1, c2, c3);
        val s1_eq = List[ColumnModel](c1, c2, c3);

        SimpleListDiff.doListDiff[ColumnModel](
            s1,
            s1_eq,
            (a, b) => {
                assert("A: " + a + "; B:" + b, a == b)
            }
        )
    
        val s2 = List[ColumnModel](c2, c3, c4);
        var i = 0;
    
    
        SimpleListDiff.doListDiff[ColumnModel](
            s1,
            s2,
            (a, b) => i = i + 1
        )
        assert("diff count invalid", i == 4);
    }
  
  
    "Auto_increment option for column diff test" is {
        val c1: ColumnModel = new ColumnModel("id", new DataType("int", Some(11)))
        c1.isAutoIncrement = true
        val c2: ColumnModel = new ColumnModel("id", new DataType("int", Some(11)))
        var i = 0;

        val m : ColumnDiffMaker.AddDiffFunction = x => {
            assert(x.isInstanceOf[AutoIncrementDiff])
            i = i + 1
            true
        }
        ColumnDiffMaker.doDiff(c1, c2, m)
        assert(i == 1)
    }

  
    "Table Diff" is {

        val c1_1: ColumnModel = new ColumnModel("id", new DataType("int", Some(11)));
        val c1_2: ColumnModel = new ColumnModel("name", new DataType("varchar", Some(100)));
        val c1_3: ColumnModel = new ColumnModel("data", new DataType("blob", None));

        val cList1 = List(c1_1, c1_2, c1_3);
        val table1: TableModel = new TableModel("table1", cList1);

    
        val c2_1: ColumnModel = new ColumnModel("id", new DataType("int", Some(20)));
        val c2_2: ColumnModel = new ColumnModel("user_name", new DataType("varchar", Some(100)));
        val c2_3: ColumnModel = new ColumnModel("data", new DataType("int", None));

        val cList2 = List(c2_1, c2_2, c2_3);
        val table2: TableModel = new TableModel("table1", cList2);
    
    

    
        var tableDiffObject: DiffType = null;
        var i = 0;

        val m: TableDiffMaker.AddDiffFunction = o => {
                tableDiffObject = o
                i = i + 1
                true
        }
        TableDiffMaker.doDiff(table1, table2, m)
        assert(i == 1)
        assert(tableDiffObject != null)
        assert(tableDiffObject.asInstanceOf[TableDiff].diffList.size == 4)
    }
  
    "Column Create Statement" is {
        val c1 = new ColumnModel("id", new DataType("int", None))
        c1.isNotNull = true
        val st = c1.toCreateStatement
        assert("Now create statement is :" + st, "id int NOT NULL".equals(st))
    }
  
    "Table Create Statement" is {
        val c1: ColumnModel = new ColumnModel("id", new DataType("int", Some(11)))
        val c2: ColumnModel = new ColumnModel("name", new DataType("varchar", Some(100)))
        val c3: ColumnModel = new ColumnModel("size", new DataType("integer", None))
        val cList = List(c1, c2, c3)
        val table = new TableModel("test_table", cList)
        val createStatement = table.toCreateStatement.trim.replaceAll("\\s[\\n\\s]*", " ")
    
    /*
        CREATE TABLE test_table (id int(11), name varchar(100), size integer);
    */
        assert("Now create Statement is: " + createStatement,"CREATE TABLE test_table (id int(11), name varchar(100), size integer);".equals(createStatement))
    }
  
  
    "Table Create statement with PK" is {
        val c1 = new ColumnModel("id", new DataType("int", Some(11)))
        val c2 = new ColumnModel("name", new DataType("varchar", Some(100)))
        val cList = List(c1, c2)
        val table = new TableModel("test_table", cList)
        table.primaryKey = new PrimaryKey("", List(c1.name, c2.name))
        val createStatement = table.toCreateStatement.trim.replaceAll("\\s[\\n\\s]*", " ")
        assert("Now create statement is: " + createStatement, "CREATE TABLE test_table (id int(11), name varchar(100), PRIMARY KEY (id, name));".equals(createStatement))
    }
  
  
    "Primary keys diff" is {
        val c1_1 = new ColumnModel("id", new DataType("int", Some(11)))
        val c1_2 = new ColumnModel("name", new DataType("varchar", Some(100)))
        val cList_1 = List(c1_1, c1_2)
        val table1 = new TableModel("test_table", cList_1)
        table1.primaryKey = new PrimaryKey("PRIMARY", List(c1_1.name, c1_2.name))

    
        val c2_1 = new ColumnModel("id", new DataType("int", Some(11)))
        val c2_2 = new ColumnModel("name", new DataType("varchar", Some(100)))
        val cList2 = List(c2_1, c2_2)
        val table2 = new TableModel("test_table", cList2)
        table2.primaryKey = new PrimaryKey("PRIMARY", List(c2_1.name))

        val m: TableDiffMaker.AddDiffFunction = x => {
            assert(x.isInstanceOf[TableDiff])
            val diffList = x.asInstanceOf[TableDiff].diffList
            assert(diffList.size == 1)
            assert(diffList(0).isInstanceOf[PrimaryKeyDiff])
            val diff = diffList(0).asInstanceOf[PrimaryKeyDiff]
            assert(diff.from == table1.primaryKey)
            assert(diff.to == table2.primaryKey)
            true
        }
        TableDiffMaker.doDiff(table1, table2, m)
    }

*/    
}
<commit_msg>[svn r739] some tests for diff building<commit_after>package ru.yandex.mysqlDiff.diff

import scalax.testing._
import ru.yandex.mysqlDiff.model._


object DiffTest extends TestSuite("Simple Diff") {


    "Column Diff" is {
    
        val c1 = new ColumnModel("c1", new DataType("int", None));
        val c1_eq = new ColumnModel("c1", new DataType("int", None));

        val nodiff = ColumnDiffBuilder.doDiff(Some(c1), Some(c1_eq));
        assert(!nodiff.isDefined)
    
        val c2 = ColumnModel("c2", new DataType("varchar", Some(20)))

        val diff = ColumnDiffBuilder.doDiff(Some(c1), Some(c2))
        assert(diff.isDefined)
        assert(diff.get.isInstanceOf[AlterColumn])
        val diff1 = diff.get.asInstanceOf[AlterColumn]
        assert(diff1.name == "c1")
        assert(diff1.renameTo == Some("c2"))

        val c3 = ColumnModel("c1", new DataType("int", Some(11)))
        val diff2O = ColumnDiffBuilder.doDiff(Some(c1), Some(c3))
        assert(diff2O.isDefined)
        val diff2 = diff2O.get.asInstanceOf[AlterColumn]
        assert(!diff2.renameTo.isDefined)
    }
  
/*
    "List Diff" is {
        val c1: ColumnModel = new ColumnModel("c1", new DataType("varchar", Some(11)));
        val c1t: ColumnModel = new ColumnModel("c1", new DataType("int", Some(11)));
        val c2: ColumnModel = new ColumnModel("c2", new DataType("varchar", Some(11)));
        val c3: ColumnModel = new ColumnModel("c3", new DataType("int", Some(11)));
        val c4: ColumnModel = new ColumnModel("c4", new DataType("int", Some(11)));

        val s1 = List[ColumnModel](c1, c2, c3);
        val s1_eq = List[ColumnModel](c1, c2, c3);

        SimpleListDiff.doListDiff[ColumnModel](
            s1,
            s1_eq,
            (a, b) => {
                assert("A: " + a + "; B:" + b, a == b)
            }
        )
    
        val s2 = List[ColumnModel](c2, c3, c4);
        var i = 0;
    
    
        SimpleListDiff.doListDiff[ColumnModel](
            s1,
            s2,
            (a, b) => i = i + 1
        )
        assert("diff count invalid", i == 4);
    }
  
  
    "Auto_increment option for column diff test" is {
        val c1: ColumnModel = new ColumnModel("id", new DataType("int", Some(11)))
        c1.isAutoIncrement = true
        val c2: ColumnModel = new ColumnModel("id", new DataType("int", Some(11)))
        var i = 0;

        val m : ColumnDiffMaker.AddDiffFunction = x => {
            assert(x.isInstanceOf[AutoIncrementDiff])
            i = i + 1
            true
        }
        ColumnDiffMaker.doDiff(c1, c2, m)
        assert(i == 1)
    }

  
    "Table Diff" is {

        val c1_1: ColumnModel = new ColumnModel("id", new DataType("int", Some(11)));
        val c1_2: ColumnModel = new ColumnModel("name", new DataType("varchar", Some(100)));
        val c1_3: ColumnModel = new ColumnModel("data", new DataType("blob", None));

        val cList1 = List(c1_1, c1_2, c1_3);
        val table1: TableModel = new TableModel("table1", cList1);

    
        val c2_1: ColumnModel = new ColumnModel("id", new DataType("int", Some(20)));
        val c2_2: ColumnModel = new ColumnModel("user_name", new DataType("varchar", Some(100)));
        val c2_3: ColumnModel = new ColumnModel("data", new DataType("int", None));

        val cList2 = List(c2_1, c2_2, c2_3);
        val table2: TableModel = new TableModel("table1", cList2);
    
    

    
        var tableDiffObject: DiffType = null;
        var i = 0;

        val m: TableDiffMaker.AddDiffFunction = o => {
                tableDiffObject = o
                i = i + 1
                true
        }
        TableDiffMaker.doDiff(table1, table2, m)
        assert(i == 1)
        assert(tableDiffObject != null)
        assert(tableDiffObject.asInstanceOf[TableDiff].diffList.size == 4)
    }
  
    "Column Create Statement" is {
        val c1 = new ColumnModel("id", new DataType("int", None))
        c1.isNotNull = true
        val st = c1.toCreateStatement
        assert("Now create statement is :" + st, "id int NOT NULL".equals(st))
    }
  
    "Table Create Statement" is {
        val c1: ColumnModel = new ColumnModel("id", new DataType("int", Some(11)))
        val c2: ColumnModel = new ColumnModel("name", new DataType("varchar", Some(100)))
        val c3: ColumnModel = new ColumnModel("size", new DataType("integer", None))
        val cList = List(c1, c2, c3)
        val table = new TableModel("test_table", cList)
        val createStatement = table.toCreateStatement.trim.replaceAll("\\s[\\n\\s]*", " ")
    
    /*
        CREATE TABLE test_table (id int(11), name varchar(100), size integer);
    */
        assert("Now create Statement is: " + createStatement,"CREATE TABLE test_table (id int(11), name varchar(100), size integer);".equals(createStatement))
    }
  
  
    "Table Create statement with PK" is {
        val c1 = new ColumnModel("id", new DataType("int", Some(11)))
        val c2 = new ColumnModel("name", new DataType("varchar", Some(100)))
        val cList = List(c1, c2)
        val table = new TableModel("test_table", cList)
        table.primaryKey = new PrimaryKey("", List(c1.name, c2.name))
        val createStatement = table.toCreateStatement.trim.replaceAll("\\s[\\n\\s]*", " ")
        assert("Now create statement is: " + createStatement, "CREATE TABLE test_table (id int(11), name varchar(100), PRIMARY KEY (id, name));".equals(createStatement))
    }
  
  
    "Primary keys diff" is {
        val c1_1 = new ColumnModel("id", new DataType("int", Some(11)))
        val c1_2 = new ColumnModel("name", new DataType("varchar", Some(100)))
        val cList_1 = List(c1_1, c1_2)
        val table1 = new TableModel("test_table", cList_1)
        table1.primaryKey = new PrimaryKey("PRIMARY", List(c1_1.name, c1_2.name))

    
        val c2_1 = new ColumnModel("id", new DataType("int", Some(11)))
        val c2_2 = new ColumnModel("name", new DataType("varchar", Some(100)))
        val cList2 = List(c2_1, c2_2)
        val table2 = new TableModel("test_table", cList2)
        table2.primaryKey = new PrimaryKey("PRIMARY", List(c2_1.name))

        val m: TableDiffMaker.AddDiffFunction = x => {
            assert(x.isInstanceOf[TableDiff])
            val diffList = x.asInstanceOf[TableDiff].diffList
            assert(diffList.size == 1)
            assert(diffList(0).isInstanceOf[PrimaryKeyDiff])
            val diff = diffList(0).asInstanceOf[PrimaryKeyDiff]
            assert(diff.from == table1.primaryKey)
            assert(diff.to == table2.primaryKey)
            true
        }
        TableDiffMaker.doDiff(table1, table2, m)
    }

*/    
}

{'fraction_non_alphanumeric': 0.134529791816224, 'fraction_numerical': 0.0312275664034458, 'mean_word_length': 2.3763936015511393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3630939', 'n_tokens_mistral': 4609, 'n_tokens_neox': 4468, 'n_words': 1113}