From c09a14e1acf4650717c4f38d98267c163f052105 Mon Sep 17 00:00:00 2001 From: Richard Ore Date: Wed, 25 Sep 2024 04:36:48 +0100 Subject: [PATCH] made no parenthesis the default convention for anonymous functions with no parameters. --- apps/nyssa/.blade/libs/qi/README.md | 4 +- apps/nyssa/.blade/libs/qi/tests/global.b | 22 +++---- apps/nyssa/.blade/libs/qi/tests/sample.spec.b | 6 +- .../nyssa/.blade/libs/qi/tests/sample2.spec.b | 6 +- apps/nyssa/.blade/libs/qi/tests/setup.spec.b | 6 +- apps/nyssa/.blade/libs/qi/tests/test.b | 24 +++---- apps/nyssa/app/server/router.b | 4 +- apps/nyssa/docs/test-assertions.md | 62 +++++++++---------- apps/nyssa/docs/test-globals.md | 56 ++++++++--------- apps/nyssa/docs/testing.md | 4 +- libs/markdown/index.b | 2 +- libs/markdown/renderer.b | 4 +- libs/process.b | 2 +- libs/template/index.b | 2 +- libs/url.b | 2 +- tests/anonymous.b | 2 +- 16 files changed, 104 insertions(+), 104 deletions(-) diff --git a/apps/nyssa/.blade/libs/qi/README.md b/apps/nyssa/.blade/libs/qi/README.md index ed68db34..cbb3c229 100644 --- a/apps/nyssa/.blade/libs/qi/README.md +++ b/apps/nyssa/.blade/libs/qi/README.md @@ -31,8 +31,8 @@ Now, let's create a test for it by creating a file `prod.test.b` in the `tests` ```py import ..prod -describe('Product test suite', @() { - it('should return 6 for 2 and 3', @() { +describe('Product test suite', @{ + it('should return 6 for 2 and 3', @{ expect(prod(2, 3)).to_be(6) }) }) diff --git a/apps/nyssa/.blade/libs/qi/tests/global.b b/apps/nyssa/.blade/libs/qi/tests/global.b index 8f68c5d9..366c91b7 100644 --- a/apps/nyssa/.blade/libs/qi/tests/global.b +++ b/apps/nyssa/.blade/libs/qi/tests/global.b @@ -3,12 +3,12 @@ var myBeverage = { sour: false, } -describe('my beverage', @() { - it('should be delicious', @() { +describe('my beverage', @{ + it('should be delicious', @{ expect(myBeverage.delicious).to_be_truthy() }); - it('should be sour', @() { + it('should be sour', @{ expect(myBeverage.sour).to_be_falsy() }) }) @@ -23,19 +23,19 @@ var binay_string_to_number = @( bin_string ) { return to_number('0b' + bin_string) } -describe('binay string to number', @() { - describe('given an invalid binary string', @() { - it('throws CustomError when composed of non-numbers', @() { - expect(@() { binay_string_to_number('abc') }).to_throw(CustomError) +describe('binay string to number', @{ + describe('given an invalid binary string', @{ + it('throws CustomError when composed of non-numbers', @{ + expect(@{ binay_string_to_number('abc') }).to_throw(CustomError) }) - it('throws CustomError when having extra whitespace', @() { - expect(@() { binay_string_to_number(' 100') }).to_throw(CustomError) + it('throws CustomError when having extra whitespace', @{ + expect(@{ binay_string_to_number(' 100') }).to_throw(CustomError) }) }) - describe('given a valid binary string', @() { - it('returns the correct number', @() { + describe('given a valid binary string', @{ + it('returns the correct number', @{ expect(binay_string_to_number('100')).to_be(4) }) }) diff --git a/apps/nyssa/.blade/libs/qi/tests/sample.spec.b b/apps/nyssa/.blade/libs/qi/tests/sample.spec.b index 48fd4749..d5af0dfb 100644 --- a/apps/nyssa/.blade/libs/qi/tests/sample.spec.b +++ b/apps/nyssa/.blade/libs/qi/tests/sample.spec.b @@ -1,5 +1,5 @@ -describe('Some testing', @() { - it('should match exactly!', @() { +describe('Some testing', @{ + it('should match exactly!', @{ expect(3).to_be(3) expect(5).to_be(5) expect(5).not().to_be(56) @@ -7,6 +7,6 @@ describe('Some testing', @() { class X {} var b = [] - expect(@() { return b[5] }).not().to_throw(X) + expect(@{ return b[5] }).not().to_throw(X) }) }) \ No newline at end of file diff --git a/apps/nyssa/.blade/libs/qi/tests/sample2.spec.b b/apps/nyssa/.blade/libs/qi/tests/sample2.spec.b index 19191ce2..d4cf157d 100644 --- a/apps/nyssa/.blade/libs/qi/tests/sample2.spec.b +++ b/apps/nyssa/.blade/libs/qi/tests/sample2.spec.b @@ -1,11 +1,11 @@ -describe('Some testing', @() { - it('should match exactly!', @() { +describe('Some testing', @{ + it('should match exactly!', @{ expect(3).to_be(3) expect(5).to_be(5) class X {} var b = [] - expect(@() { return b[5] }).to_throw() + expect(@{ return b[5] }).to_throw() }) }) \ No newline at end of file diff --git a/apps/nyssa/.blade/libs/qi/tests/setup.spec.b b/apps/nyssa/.blade/libs/qi/tests/setup.spec.b index 3b056e95..b413226f 100644 --- a/apps/nyssa/.blade/libs/qi/tests/setup.spec.b +++ b/apps/nyssa/.blade/libs/qi/tests/setup.spec.b @@ -1,10 +1,10 @@ import ..setup -describe('Importing', @() { - it('should have a valid command', @() { +describe('Importing', @{ + it('should have a valid command', @{ expect(setup.cmd).to_be_string() }) - it('should have a correct file path', @() { + it('should have a correct file path', @{ expect(setup.path).to_contain('qi') }) }) diff --git a/apps/nyssa/.blade/libs/qi/tests/test.b b/apps/nyssa/.blade/libs/qi/tests/test.b index 8fc2e96b..52bc24c0 100644 --- a/apps/nyssa/.blade/libs/qi/tests/test.b +++ b/apps/nyssa/.blade/libs/qi/tests/test.b @@ -3,8 +3,8 @@ var can = { ounces: 12, } -describe('the can', @() { - it('has 12 ounces', @() { +describe('the can', @{ + it('has 12 ounces', @{ expect(can.ounces).to_be(12) class A { @@ -17,7 +17,7 @@ describe('the can', @() { expect(10.5).to_be_number().to_be_less_than(20) }) - it('has a sophisticated name', @() { + it('has a sophisticated name', @{ expect(can.name).to_be('pamplemousse') expect([1, 2, 3]).to_have_length(3) @@ -25,7 +25,7 @@ describe('the can', @() { expect('').not().to_have_length(5) }) - it('should pass this tests', @() { + it('should pass this tests', @{ class A { testing() {} @testing() {} @@ -46,8 +46,8 @@ describe('the can', @() { }) def do_something(id) { - if id == 1 return @() { do_another_thing() } - else return @() { do_something_else() } + if id == 1 return @{ do_another_thing() } + else return @{ do_something_else() } } class Set { @@ -55,8 +55,8 @@ class Set { @itern() {} } -describe('grapefruits', @() { - it('should be a grape', @() { +describe('grapefruits', @{ + it('should be a grape', @{ expect('grapefruits').to_match('grape') expect(do_something(1)).to_be_function() @@ -64,12 +64,12 @@ describe('grapefruits', @() { expect(Exception).to_be_class() }) - it('should be valid type', @() { + it('should be valid type', @{ expect({age: 10}).to_be_dict() expect(bytes(0)).to_be_bytes() }) - it('should be enumerable', @() { + it('should be enumerable', @{ expect([]).to_be_iterable() expect({}).to_be_iterable() expect(Set()).to_be_iterable() @@ -85,8 +85,8 @@ def drink_flavor(flavor) { # Do some other stuff } -describe('testing to throw', @() { - it('throws on octopus', @() { +describe('testing to throw', @{ + it('throws on octopus', @{ def drink_octopus() { drink_flavor('octopus') } diff --git a/apps/nyssa/app/server/router.b b/apps/nyssa/app/server/router.b index d348583e..52ba50a4 100644 --- a/apps/nyssa/app/server/router.b +++ b/apps/nyssa/app/server/router.b @@ -63,7 +63,7 @@ def _setup_session(req, res) { } # bind '.clear_session()' to response - res.clear_session = @() { + res.clear_session = @{ res.session = {} # just for simplicity @@ -71,7 +71,7 @@ def _setup_session(req, res) { } } -var _template_setup = @() { +var _template_setup = @{ var tpl = template() tpl.set_root(os.join_paths(setup.NYSSA_DIR, setup.TEMPLATES_DIR)) for name, fn in template_ext() { diff --git a/apps/nyssa/docs/test-assertions.md b/apps/nyssa/docs/test-assertions.md index bee33f26..c39f0986 100644 --- a/apps/nyssa/docs/test-assertions.md +++ b/apps/nyssa/docs/test-assertions.md @@ -8,8 +8,8 @@ When writing tests you often need to check that a value meets certain criterias. The `expect` function is used every time you want to test a value. You will rarely call `expect` by itself. Instead, you will use `expect` along with a "matcher" function to assert something about a value. Let's say you have a method `name_of_app()` which is supposed to return the string `'qi'`. Here's how you would test that: ```blade -describe('Name of app test', @() { - it('should be qi', @() { +describe('Name of app test', @{ + it('should be qi', @{ expect(name_of_app()).to_be('qi') }) }) @@ -26,8 +26,8 @@ The argument to `expect` should be the value that your code produces, and any ar If you know how to test something, `.not()` lets you test its opposite. For example, this code tests that the name of the application is `not` `'qi'`. ```blade -describe('Name of app test', @() { - it('should be qi', @() { +describe('Name of app test', @{ + it('should be qi', @{ expect(name_of_app()).not().to_be('qi') }) }) @@ -54,12 +54,12 @@ var can = { ounces: 12, } -describe('the can', @() { - it('has 12 ounces', @() { +describe('the can', @{ + it('has 12 ounces', @{ expect(can.ounces).to_be(12) }) - it('has a sophisticated name', @() { + it('has a sophisticated name', @{ expect(can.name).to_be('pamplemousse') }) }) @@ -74,7 +74,7 @@ def bloop() { return nil } -it('should return nil', @() { +it('should return nil', @{ expect(bloop()).to_be_nil() }) ``` @@ -103,7 +103,7 @@ if thirsty() { You may not care what `get_errors` returns, specifically - it might return `true`, `[1]`, or anything that's true in Blade, and your code would still work. So if you want to test you are thirsty before drinking some La Croix, you could write: ```blade -it('should be thirsty before drinking La Croix', @() { +it('should be thirsty before drinking La Croix', @{ drink_some_lacroix() expect(thirsty()).to_be_truthy() }) @@ -123,7 +123,7 @@ if !get_errors() { You may not care what `get_errors` returns, specifically - it might return `false`, `nil`, or `-1`, and your code would still work. So if you want to test there are no errors after drinking some La Croix, you could write: ```blade -it('does not lead to errors when drinking La Croix', @() { +it('does not lead to errors when drinking La Croix', @{ drink_some_lacroix() expect(get_errors()).to_be_falsy() }) @@ -134,7 +134,7 @@ it('does not lead to errors when drinking La Croix', @() { Use `.to_be_greater_than` to compare `received > expected` for number or `received.length() > expected` for string. For example, test that `ounces_per_can()` returns a value of more than 10 ounces: ```blade -it('is more than 10 ounces per can', @() { +it('is more than 10 ounces per can', @{ expect(ounces_per_can()).to_be_greater_than(10) }) ``` @@ -144,7 +144,7 @@ it('is more than 10 ounces per can', @() { Use `.to_be_greater_than_or_equal` to compare `received >= expected` for number or `received.length() >= expected` for string. For example, test that `ounces_per_can()` returns a value of more than or equal to 10 ounces: ```blade -it('is more than or equal to 10 ounces per can', @() { +it('is more than or equal to 10 ounces per can', @{ expect(ounces_per_can()).to_be_greater_than_or_equal(10) }) ``` @@ -154,7 +154,7 @@ it('is more than or equal to 10 ounces per can', @() { Use `.to_be_less_than` to compare `received < expected` for number or `received.length() < expected` for string. For example, test that `ounces_per_can()` returns a value of less than 10 ounces: ```blade -it('is less than 10 ounces per can', @() { +it('is less than 10 ounces per can', @{ expect(ounces_per_can()).to_be_less_than(10) }) ``` @@ -164,7 +164,7 @@ it('is less than 10 ounces per can', @() { Use `.to_be_less_than_or_equal` to compare `received <= expected` for number or `received.length() <= expected` for string. For example, test that `ounces_per_can()` returns a value of less than or equal to 10 ounces: ```blade -it('is less than or equal to 10 ounces per can', @() { +it('is less than or equal to 10 ounces per can', @{ expect(ounces_per_can()).to_be_less_than_or_equal(10) }) ``` @@ -176,8 +176,8 @@ Use `.to_match` to check that a string matches a regular expression. For example, you might not know what exactly `essay_on_the_best_flavor()` returns, but you know it's a really long string, and the substring grapefruit should be in there somewhere. You can test this with: ```blade -describe('an essay on the best flavor', @() { - it('mentions grapefruit', @() { +describe('an essay on the best flavor', @{ + it('mentions grapefruit', @{ expect(essay_on_the_best_flavor()).to_match('/grapefruit/i') }) }) @@ -186,8 +186,8 @@ describe('an essay on the best flavor', @() { This matcher also accepts a string, which it will try to match: ```blade -describe('grapefruits', @() { - it('should be a grape', @() { +describe('grapefruits', @{ + it('should be a grape', @{ expect('grapefruits').to_match('grape') }) }) @@ -200,7 +200,7 @@ Use `.to_contain` when you want to check that an item is in an list or dictionar For example, if `get_all_flavors()` returns an list of flavors and you want to be sure that lime is in there, you can write: ```blade -it('should contain lime', @() { +it('should contain lime', @{ expect(get_all_flavors()).to_contain('lime') }) ``` @@ -210,8 +210,8 @@ it('should contain lime', @() { Use `.to_throw` to test that a function throws when it is called. For example, if we want to test that `drink_flavor('octopus')` throws, because octopus flavor is too disgusting to drink, we could write: ```blade -it('throws on octopus', @() { - expect(@() { +it('throws on octopus', @{ + expect(@{ drink_flavor('octopus') }).to_throw() }) @@ -242,7 +242,7 @@ def drink_flavor(flavor) { We could test the error thrown in several ways: ```blade -it('throws on octopus', @() { +it('throws on octopus', @{ def drink_octopus() { drink_flavor('octopus') } @@ -287,8 +287,8 @@ Use `.to_be_function` when you want to check if a value is a function or a closu ```blade def do_something(id) { - if id == 1 return @() { do_another_thing() } - else return @() { do_something_else() } + if id == 1 return @{ do_another_thing() } + else return @{ do_something_else() } } ``` @@ -359,7 +359,7 @@ expect(return_class()).to_have_decorator('testing') Use `.to_be_boolean` to check for `true` or `false` values. For example, test that `user_is_admin()` returns a value of `true` or `false`: ```blade -it('should be true or false', @() { +it('should be true or false', @{ expect(user_is_admin()).to_be_boolean() }) ``` @@ -369,7 +369,7 @@ it('should be true or false', @() { Use `.to_be_number` to check that a value is a number without requiring any specific number. For example, test that `number_of_cans()` returns a valid number: ```blade -it('should be a number', @() { +it('should be a number', @{ expect(number_of_cans()).to_be_number() }) ``` @@ -379,7 +379,7 @@ it('should be a number', @() { Use `.to_be_string` to check that a value is a string without requiring any specific content. For example, test that `name_of_king()` returns a valid string: ```blade -it('should be a string', @() { +it('should be a string', @{ expect(name_of_king()).to_be_string() }) ``` @@ -389,7 +389,7 @@ it('should be a string', @() { Use `.to_be_list` to check that a value is a list without requiring any specific content. For example, test that `fruits()` returns a valid list: ```blade -it('should be a string', @() { +it('should be a string', @{ expect(fruits()).to_be_list() }) ``` @@ -399,7 +399,7 @@ it('should be a string', @() { Use `.to_be_dict` to check that a value is a dictionary without requiring any specific content. For example, test that `{age: 10}` returns a valid dictionary: ```blade -it('should be a dictionary', @() { +it('should be a dictionary', @{ expect({age: 10}).to_be_dict() }) ``` @@ -409,7 +409,7 @@ it('should be a dictionary', @() { Use `.to_be_class` to check that a value is a class and not an instance. For example, test that `Exception` is actually a class: ```blade -it('should be a list', @() { +it('should be a list', @{ expect(Exception).to_be_class() }) ``` @@ -428,7 +428,7 @@ class Set { The following test will show that it's as much an iterable as a list or dictionary can be. ```blade -it('should be enumerable', @() { +it('should be enumerable', @{ expect([]).to_be_iterable() expect({}).to_be_iterable() expect(Set()).to_be_iterable() diff --git a/apps/nyssa/docs/test-globals.md b/apps/nyssa/docs/test-globals.md index e1ddffd1..ca480919 100644 --- a/apps/nyssa/docs/test-globals.md +++ b/apps/nyssa/docs/test-globals.md @@ -14,12 +14,12 @@ var myBeverage = { sour: false, } -describe('my beverage', @() { - it('should be delicious', @() { +describe('my beverage', @{ + it('should be delicious', @{ expect(myBeverage.delicious).to_be_truthy() }); - it('should be sour', @() { + it('should be sour', @{ expect(myBeverage.sour).to_be_falsy() }) }) @@ -36,19 +36,19 @@ var binay_string_to_number = @( bin_string ) { return to_number('0b' + bin_string) } -describe('binay string to number', @() { - describe('given an invalid binary string', @() { - it('throws CustomError when composed of non-numbers', @() { - expect(@() { binay_string_to_number('abc') }).to_throw(CustomError) +describe('binay string to number', @{ + describe('given an invalid binary string', @{ + it('throws CustomError when composed of non-numbers', @{ + expect(@{ binay_string_to_number('abc') }).to_throw(CustomError) }) - it('throws CustomError when having extra whitespace', @() { - expect(@() { binay_string_to_number(' 100') }).to_throw(CustomError) + it('throws CustomError when having extra whitespace', @{ + expect(@{ binay_string_to_number(' 100') }).to_throw(CustomError) }) }) - describe('given a valid binary string', @() { - it('returns the correct number', @() { + describe('given a valid binary string', @{ + it('returns the correct number', @{ expect(binay_string_to_number('100')).to_be(4) }) }) @@ -60,7 +60,7 @@ describe('binay string to number', @() { The `it(name, fn)` function is the entry point for tests in a test suite. For example, let's say there's a function `inches_of_rain()` that should return zero. Your whole test could be: ```blade -it('did not rain', @() { +it('did not rain', @{ expect(inches_of_rain()).to_be(0) }) ``` @@ -85,17 +85,17 @@ For example: ```blade var global_db = make_global_db() -before_all(@() { +before_all(@{ # Clears the database and adds some testing data. - return globalDatabase.clear(@() { + return globalDatabase.clear(@{ return globalDatabase.insert({testData: 'foo'}) }) }) # Since we only set up the database once in this example, it's important # that our tests don't modify it. -describe('Before all', @() { - it('can find things', @() { +describe('Before all', @{ + it('can find things', @{ return global_db.find('thing', {}, @(results) { expect(results.length()).to_be_greater_than(0) }) @@ -118,18 +118,18 @@ def clean_up_db(db) { db.clean_up() } -after_all(@() { +after_all(@{ clean_up_db(global_db) }); -describe('confirming after_all works', @() { - it('can find things', @() { +describe('confirming after_all works', @{ + it('can find things', @{ return global_db.find('thing', {}, @(results) { expect(results.length()).to_be_greater_than(0) }) }) - it('can insert a thing', @() { + it('can insert a thing', @{ return global_db.insert('thing', make_thing(), @(response) { expect(response.success).to_be_truthy() }) @@ -150,20 +150,20 @@ For example: ```blade var global_db = make_global_db() -before_each(@() { +before_each(@{ # Clears the database and adds some testing data. global_db.clear() global_db.insert({testData: 'foo'}); }) -describe('confirming before_each works', @() { - it('can find things', @() { +describe('confirming before_each works', @{ + it('can find things', @{ return global_db.find('thing', {}, @(results) { expect(results.length()).to_be_greater_than(0) }) }) - it('can insert a thing', @() { + it('can insert a thing', @{ return global_db.insert('thing', make_thing(), @(response) { expect(response.success).to_be_truthy() }) @@ -186,18 +186,18 @@ def clean_up_db(db) { db.clean_up() } -after_each(@() { +after_each(@{ clean_up_db(global_db) }) -describe('confirming after_each works', @() { - it('can find things', @() { +describe('confirming after_each works', @{ + it('can find things', @{ return global_db.find('thing', {}, @(results) { expect(results.length()).to_be_greater_than(0) }) }) - it('can insert a thing', @() { + it('can insert a thing', @{ return global_db.insert('thing', make_thing(), @(response) { expect(response.success).to_be_truthy() }) diff --git a/apps/nyssa/docs/testing.md b/apps/nyssa/docs/testing.md index 691aacfc..f99f56fc 100644 --- a/apps/nyssa/docs/testing.md +++ b/apps/nyssa/docs/testing.md @@ -19,8 +19,8 @@ Now, let's create a test for it by creating a file `prod.test.b` in the `tests` ```blade import ..prod -describe('Product test suite', @() { - it('should return 6 for 2 and 3', @() { +describe('Product test suite', @{ + it('should return 6 for 2 and 3', @{ expect(prod(2, 3)).to_be(6) }) }) diff --git a/libs/markdown/index.b b/libs/markdown/index.b index 3df573d2..2c6ac992 100644 --- a/libs/markdown/index.b +++ b/libs/markdown/index.b @@ -163,7 +163,7 @@ class Markdown { * var md = markdown() * * # enable everything - * md.validate_link = @(){ return true; } + * md.validate_link = @{ return true; } * ``` * * @param {string} url diff --git a/libs/markdown/renderer.b b/libs/markdown/renderer.b index e4c0de01..5d6229d4 100644 --- a/libs/markdown/renderer.b +++ b/libs/markdown/renderer.b @@ -122,8 +122,8 @@ class Renderer { * ```blade * import markdown as md * - * md.renderer.rules.strong_open = @() { return '' } - * md.renderer.rules.strong_close = @() { return '' } + * md.renderer.rules.strong_open = @{ return '' } + * md.renderer.rules.strong_close = @{ return '' } * * var result = md.render_inline(...) * ``` diff --git a/libs/process.b b/libs/process.b index b4bba918..72d19810 100644 --- a/libs/process.b +++ b/libs/process.b @@ -16,7 +16,7 @@ * s.set({name: 'Richard', age: 3.142}) * }, paged) * - * pr.on_complete(@(){ + * pr.on_complete(@{ * echo paged.get() * }) * diff --git a/libs/template/index.b b/libs/template/index.b index 15a4094c..c5a993aa 100644 --- a/libs/template/index.b +++ b/libs/template/index.b @@ -371,7 +371,7 @@ * For example, consider the following template function defined to return the base url of a website. * * ```blade - * tpl.register_function('base_url', @() { + * tpl.register_function('base_url', @{ * return 'https://localhost:8000' * }) * ``` diff --git a/libs/url.b b/libs/url.b index 81d5c9e4..525afd75 100644 --- a/libs/url.b +++ b/libs/url.b @@ -493,7 +493,7 @@ def parse(url, strict) { iter var i = 0; i < url.length(); i++ { # simple anonymous function to scan port - var _scan_port = @() { + var _scan_port = @{ var _port = '' i++ while i < url.length() and types.digit(url[i]) { # id_digit diff --git a/tests/anonymous.b b/tests/anonymous.b index c7768450..dfc0b797 100644 --- a/tests/anonymous.b +++ b/tests/anonymous.b @@ -12,7 +12,7 @@ def main() { var g = 'Coke' echo g - var concat = @() { + var concat = @{ g += ' is the best' } concat()