<commit_before>import XCTest
import GRDB

class RowAdapterTests: GRDBTestCase {
    
    func testRowAdapter() {
        let dbQueue = DatabaseQueue()
        dbQueue.inDatabase { db in
            let adapter = RowAdapter(
                mapping: ["id": "fooid", "val": "fooval"],
                subrows: [
                    "foo": ["id": "barid", "val": "barval"],
                    "odd": ["id": "missingid"]])
            let row = Row.fetchOne(db, "SELECT 1 AS fooid, 'toto' AS fooval, 2 as barid, 'tata' AS barval", adapter: adapter)!
            
            print(row)                  // <Row id:1 val:"toto">
            XCTAssertEqual(row.count, 2)
            XCTAssertEqual(row.value(named: "id") as Int, 1)
            XCTAssertEqual(row.value(named: "val") as String, "toto")
            XCTAssertEqual(row.databaseValue(named: "id"), 1.databaseValue)
            XCTAssertEqual(row.databaseValue(named: "val"), "toto".databaseValue)
            XCTAssertTrue(row.value(named: "barid") == nil)
            XCTAssertTrue(row.value(named: "missing") == nil)
            XCTAssertTrue(row.hasColumn("id"))
            XCTAssertTrue(row.hasColumn("val"))
            XCTAssertFalse(row.hasColumn("barid"))
            XCTAssertFalse(row.hasColumn("missing"))
            // TODO: test row.value(atIndex: 0) and row.value(atIndex: 1)
            // TODO: test for (key, value) in row { ... }
            
            let row2 = row.subrows["foo"]!
            XCTAssertEqual(row2.count, 2)
            XCTAssertEqual(row2.value(named: "id") as Int, 2)
            XCTAssertEqual(row2.value(named: "val") as String, "tata")
            
            let row3 = row.subrows["odd"]!
            XCTAssertEqual(row3.count, 1)
            XCTAssertTrue(row3.value(named: "id") == nil)
        }
    }

}<commit_msg>More RowAdapter tests<commit_after>import XCTest
import GRDB

class RowAdapterTests: GRDBTestCase {
    
    func testRowAdapter() {
        let dbQueue = DatabaseQueue()
        dbQueue.inDatabase { db in
            let adapter = RowAdapter(
                mapping: ["id": "fooid", "val": "fooval"],
                subrows: [
                    "foo": ["id": "barid", "val": "barval"],
                    "odd": ["id": "missingid"]])
            let row = Row.fetchOne(db, "SELECT 1 AS fooid, 'foo' AS fooval, 2 as barid, 'bar' AS barval", adapter: adapter)!
            
            // # Row values
            
            XCTAssertEqual(row.count, 2)
            XCTAssertEqual(row.value(named: "id") as Int, 1)
            XCTAssertEqual(row.value(named: "val") as String, "foo")
            XCTAssertEqual(row.databaseValue(named: "id"), 1.databaseValue)
            XCTAssertEqual(row.databaseValue(named: "val"), "foo".databaseValue)
            XCTAssertTrue(row.value(named: "barid") == nil)
            XCTAssertTrue(row.value(named: "missing") == nil)
            XCTAssertTrue(row.hasColumn("id"))
            XCTAssertTrue(row.hasColumn("val"))
            XCTAssertFalse(row.hasColumn("barid"))
            XCTAssertFalse(row.hasColumn("missing"))
            // TODO: test row.value(atIndex: 0) and row.value(atIndex: 1)
            // TODO: test for (key, value) in row { ... }
            
            
            // # Row equality
            
            // One of this tests is failing - can't know which one because dictionaries are unordered.
            // TODO: think about that.
            let altRow1 = Row.fetchOne(db, "SELECT 1 AS id, 'foo' AS val")!
            XCTAssertEqual(row, altRow1)
            let altRow2 = Row.fetchOne(db, "SELECT 'foo' AS val, 1 AS id")!
            XCTAssertEqual(row, altRow2)
            
            
            // # Subrows
            
            let row2 = row.subrows["foo"]!
            XCTAssertEqual(row2.count, 2)
            XCTAssertEqual(row2.value(named: "id") as Int, 2)
            XCTAssertEqual(row2.value(named: "val") as String, "bar")
            
            let row3 = row.subrows["odd"]!
            XCTAssertEqual(row3.count, 1)
            XCTAssertTrue(row3.value(named: "id") == nil)
        }
    }

}
{'fraction_non_alphanumeric': 0.1343030303030303, 'fraction_numerical': 0.009939393939393939, 'mean_word_length': 1.8337912087912087, 'pattern_counts': {'":': 14, '<': 4, '<?xml version=': 0, '>': 4, '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': '5097026', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1240, 'n_words': 283}