<commit_before>package tornadofx

import org.junit.Assert
import org.junit.Test

open class ViewModelTests {

    @Test fun simple_commit() {
        val person = Person("John")
        val viewModel = PersonViewModel(person)

        viewModel.name.value = "Jay"
        Assert.assertEquals(person.name, "John")
        viewModel.commit()
        Assert.assertEquals(person.name, "Jay")
    }

    @Test fun pojo_commit() {
        val person = JavaPerson()
        person.name = "John"
        val viewModel = JavaPersonViewModel(person)

        viewModel.name.value = "Jay"
        Assert.assertEquals(person.name, "John")
        viewModel.commit()
        Assert.assertEquals(person.name, "Jay")
    }

    @Test fun var_commit_check_dirty_state() {
        val person = Person("John")
        val viewModel = PersonVarViewModel(person)

        Assert.assertFalse(viewModel.isDirty())

        viewModel.name.value = "Jay"
        Assert.assertEquals(person.name, "John")
        Assert.assertTrue(viewModel.isDirty())

        viewModel.commit()
        Assert.assertEquals(person.name, "Jay")
        Assert.assertFalse(viewModel.isDirty())
    }

    @Test fun inline_viewmodel() {
        val person = Person("John")

        val viewModel = object : ViewModel() {
            val name = person.nameProperty().wrap()
        }

        viewModel.name.value = "Jay"
        Assert.assertEquals(person.name, "John")
        viewModel.commit()
        Assert.assertEquals(person.name, "Jay")
    }

}

class PersonViewModel(person: Person) : ViewModel() {
    val name = person.nameProperty().wrap()
}

class JavaPersonViewModel(person: JavaPerson) : ViewModel() {
    val name = person.wrap(JavaPerson::getName, JavaPerson::setName)
}

class PersonVarViewModel(person: Person) : ViewModel() {
    val name = person.wrap(Person::name)
}<commit_msg>Added dirty state tracking to ViewModel<commit_after>package tornadofx

import org.junit.Assert
import org.junit.Test

open class ViewModelTests {

    @Test fun simple_commit() {
        val person = Person("John")
        val viewModel = PersonViewModel(person)

        viewModel.name.value = "Jay"
        Assert.assertEquals(person.name, "John")
        viewModel.commit()
        Assert.assertEquals(person.name, "Jay")
    }

    @Test fun pojo_commit() {
        val person = JavaPerson()
        person.name = "John"
        val viewModel = JavaPersonViewModel(person)

        viewModel.name.value = "Jay"
        Assert.assertEquals(person.name, "John")
        viewModel.commit()
        Assert.assertEquals(person.name, "Jay")
    }

    @Test fun var_commit_check_dirty_state() {
        val person = Person("John")
        val viewModel = PersonViewModel(person)

        Assert.assertFalse(viewModel.isDirty())

        viewModel.name.value = "Jay"
        Assert.assertEquals(person.name, "John")
        Assert.assertTrue(viewModel.isDirty())

        viewModel.commit()
        Assert.assertEquals(person.name, "Jay")
        Assert.assertFalse(viewModel.isDirty())
    }

    @Test fun inline_viewmodel() {
        val person = Person("John")

        val viewModel = object : ViewModel() {
            val name = person.nameProperty().wrap()
        }

        viewModel.name.value = "Jay"
        Assert.assertEquals(person.name, "John")
        viewModel.commit()
        Assert.assertEquals(person.name, "Jay")
    }

}

class PersonViewModel(person: Person) : ViewModel() {
    val name = person.nameProperty().wrap()
}

class JavaPersonViewModel(person: JavaPerson) : ViewModel() {
    val name = person.wrap(JavaPerson::getName, JavaPerson::setName)
}

class PersonVarViewModel(person: Person) : ViewModel() {
    val name = person.wrap(Person::name)
}
{'fraction_non_alphanumeric': 0.12048192771084337, 'fraction_numerical': 0.0, 'mean_word_length': 2.7737373737373736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4219191', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1056, 'n_words': 213}