77 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Factor
		
	
	
		
			Executable File
		
	
			
		
		
	
	
			77 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Factor
		
	
	
		
			Executable File
		
	
USING: io io.files io.launcher kernel namespaces
 | 
						|
prettyprint tools.test db.sqlite db sequences
 | 
						|
continuations db.types db.tuples unicode.case ;
 | 
						|
IN: db.sqlite.tests
 | 
						|
 | 
						|
: db-path "test.db" temp-file ;
 | 
						|
: test.db db-path sqlite-db ;
 | 
						|
 | 
						|
[ ] [ [ db-path delete-file ] ignore-errors ] unit-test
 | 
						|
 | 
						|
[ ] [
 | 
						|
    test.db [
 | 
						|
        "create table person (name varchar(30), country varchar(30))" sql-command
 | 
						|
        "insert into person values('John', 'America')" sql-command
 | 
						|
        "insert into person values('Jane', 'New Zealand')" sql-command
 | 
						|
    ] with-db
 | 
						|
] unit-test
 | 
						|
 | 
						|
 | 
						|
[ { { "John" "America" } { "Jane" "New Zealand" } } ] [
 | 
						|
    test.db [
 | 
						|
        "select * from person" sql-query
 | 
						|
    ] with-db
 | 
						|
] unit-test
 | 
						|
 | 
						|
[ { { "1" "John" "America" } { "2" "Jane" "New Zealand" } } ]
 | 
						|
[ test.db [ "select rowid, * from person" sql-query ] with-db ] unit-test
 | 
						|
 | 
						|
[ ] [
 | 
						|
    test.db [
 | 
						|
        "insert into person(name, country) values('Jimmy', 'Canada')"
 | 
						|
        sql-command
 | 
						|
    ] with-db
 | 
						|
] unit-test
 | 
						|
 | 
						|
[
 | 
						|
    {
 | 
						|
        { "1" "John" "America" }
 | 
						|
        { "2" "Jane" "New Zealand" }
 | 
						|
        { "3" "Jimmy" "Canada" }
 | 
						|
    }
 | 
						|
] [ test.db [ "select rowid, * from person" sql-query ] with-db ] unit-test
 | 
						|
 | 
						|
[
 | 
						|
    test.db [
 | 
						|
        [
 | 
						|
            "insert into person(name, country) values('Jose', 'Mexico')" sql-command
 | 
						|
            "insert into person(name, country) values('Jose', 'Mexico')" sql-command
 | 
						|
            "oops" throw
 | 
						|
        ] with-transaction
 | 
						|
    ] with-db
 | 
						|
] must-fail
 | 
						|
 | 
						|
[ 3 ] [
 | 
						|
    test.db [
 | 
						|
        "select * from person" sql-query length
 | 
						|
    ] with-db
 | 
						|
] unit-test
 | 
						|
 | 
						|
[
 | 
						|
] [
 | 
						|
    test.db [
 | 
						|
        [
 | 
						|
            "insert into person(name, country) values('Jose', 'Mexico')"
 | 
						|
            sql-command
 | 
						|
            "insert into person(name, country) values('Jose', 'Mexico')"
 | 
						|
            sql-command
 | 
						|
        ] with-transaction
 | 
						|
    ] with-db
 | 
						|
] unit-test
 | 
						|
 | 
						|
[ 5 ] [
 | 
						|
    test.db [
 | 
						|
        "select * from person" sql-query length
 | 
						|
    ] with-db
 | 
						|
] unit-test
 |