<commit_before><!DOCTYPE html>
<html>
<head>
	<title>Lawnchair Query Plugin Spec</title>
	<link rel="stylesheet" href="../lib/qunit.css" type="text/css" media="screen" title="no title" charset="utf-8">
	
	<script src="../lib/lawnchair.js"></script>
	<script src="../lib/qunit.js"></script>
    <script src="../lib/json2.js"></script>
	<script src="../lib/lawnchair-query.js"></script>
	<script>
		/*
        searching
        
        store.where('record.name === "brian"') 
        store.where('record.name != ?', username)
        store.where('record.shoe === ? && record.shoe.active === ?', 'nike', true, function(results) { 
        
        })  
        
        sorting
        
        store.where('name === "brian").asc('active')
        store.where('name === "brian").desc('active')
        
        plugin (chaining) compatability
        
        Products.where('price > 0').count('console.log(count)')
        Fluids.where('!empty && contents === "beer"').sum('amount', 'console.log(sum)')
        People.where('active').each('person.active = false; this.save(person)') 
        Movies.where('category === "scifi"').asc('rating').page(1, function(movie) { console.log(movie}))  
		*/
		
		var store = new Lawnchair('test-plugins', function() { 
			
			var store = this

            module('Query', {setup:function(){ store.nuke() }})

            test('sanity', function() {
                expect(4)
                ok(store.where, 'where defined')
                ok(store.asc,   'asc defined')
                ok(store.desc,  'desc defined')
                stop()
                store.all(function(r){
                    start()
                    equals(r.length, 0, 'store should be empty')
                })
            })
            
            test('where, asc and desc', function() {
				store.batch([{a:3},{a:2},{a:1},{a:5},{a:4}], function() {
                    this.all('equals(records.length, 5, "has five records saved")')
                    this.where('record.a === 1', function(a) {
                        ok(a, 'can query on a property') 
                    }) 
                    this.where('record.a === ?', 1, function(a){
                        ok(a, 'can interpolate query with variable')
                    })
                    this.where('record.a === ? && record != ?', 1, undefined, function(a){
                        ok(a, 'can interpolate query with many  variables')
                    })
                    this.where('record.a === 1').all('ok(records, "chaining works")')
                    this.where('record.a === 1', 'ok(records, "terse callback works")')
                    this.where('typeof record != "undefined"').asc('a', function(records) {
                        ok(records, "has records")
                        equals(records[0].a, 1, "first record is 1")
                        equals(records[1].a, 2, "second record is 2")
                        equals(records[2].a, 3, "third record is 3")
                        equals(records[3].a, 4, "forth record is 4")
                        equals(records[4].a, 5, "fifth record is 5")
                    })
                    this.where('typeof record != "undefined"').desc('a', function(records) {
                        ok(records, "has records")
                        equals(records.length, 5, "has five records in collection")
                        equals(records[0].a, 5, "first record is 5")
                        equals(records[1].a, 4, "second record is 4")
                        equals(records[2].a, 3, "third record is 3")
                        equals(records[3].a, 2, "forth record is 2")
                        equals(records[4].a, 1, "fifth record is 1")
                    })
                })
            })<commit_msg>as per http://westcoastlogic.com/lawnchair/plugins/ where("var_name = 'value'") should work in addition to where("record.var_name = 'value'"). Added qunit tests to reflect this. Tests fail<commit_after><!DOCTYPE html>
<html>
<head>
	<title>Lawnchair Query Plugin Spec</title>
	<link rel="stylesheet" href="../lib/qunit.css" type="text/css" media="screen" title="no title" charset="utf-8">
	
	<script src="../lib/lawnchair.js"></script>
	<script src="../lib/qunit.js"></script>
    <script src="../lib/json2.js"></script>
	<script src="../lib/lawnchair-query.js"></script>
	<script>
		/*
        searching
        
        store.where('record.name === "brian"') 
        store.where('record.name != ?', username)
        store.where('record.shoe === ? && record.shoe.active === ?', 'nike', true, function(results) { 
        
        })  
        
        sorting
        
        store.where('name === "brian").asc('active')
        store.where('name === "brian").desc('active')
        
        plugin (chaining) compatability
        
        Products.where('price > 0').count('console.log(count)')
        Fluids.where('!empty && contents === "beer"').sum('amount', 'console.log(sum)')
        People.where('active').each('person.active = false; this.save(person)') 
        Movies.where('category === "scifi"').asc('rating').page(1, function(movie) { console.log(movie}))  
		*/
		
		var store = new Lawnchair('test-plugins', function() { 
			
			var store = this

            module('Query', {setup:function(){ store.nuke() }})

            test('sanity', function() {
                expect(4)
                ok(store.where, 'where defined')
                ok(store.asc,   'asc defined')
                ok(store.desc,  'desc defined')
                stop()
                store.all(function(r){
                    start()
                    equals(r.length, 0, 'store should be empty')
                })
            })
            
            test('where, asc and desc', function() {
				store.batch([{a:3},{a:2},{a:1},{a:5},{a:4}], function() {
                    this.all('equals(records.length, 5, "has five records saved")')
                    this.where('record.a === 1', function(a) {
                        ok(a, 'can query on a property') 
                    }) 
                    this.where('a === ?', 1, function(a){
                        equals(records[2], 'can interpolate query with variable ("a === ?")')
                    })
                    this.where('record.a === ?', 1, function(a){
                        equals(records[2], 'can interpolate query with variable ("record.a === ?")')
                    })
                    this.where('record.a === ? && record != ?', 1, undefined, function(a){
                        ok(a, 'can interpolate query with many  variables')
                    })
                    this.where('record.a === 1').all('ok(records, "chaining works")')
                    this.where('record.a === 1', 'ok(records, "terse callback works")')
                    this.where('typeof record != "undefined"').asc('a', function(records) {
                        ok(records, "has records")
                        equals(records[0].a, 1, "first record is 1")
                        equals(records[1].a, 2, "second record is 2")
                        equals(records[2].a, 3, "third record is 3")
                        equals(records[3].a, 4, "forth record is 4")
                        equals(records[4].a, 5, "fifth record is 5")
                    })
                    this.where('typeof record != "undefined"').desc('a', function(records) {
                        ok(records, "has records")
                        equals(records.length, 5, "has five records in collection")
                        equals(records[0].a, 5, "first record is 5")
                        equals(records[1].a, 4, "second record is 4")
                        equals(records[2].a, 3, "third record is 3")
                        equals(records[3].a, 2, "forth record is 2")
                        equals(records[4].a, 1, "fifth record is 1")
                    })
                })
            })
{'fraction_non_alphanumeric': 0.1669186192995717, 'fraction_numerical': 0.012471655328798186, 'mean_word_length': 1.615815485996705, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, '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': '6307641', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2136, 'n_words': 474}