<commit_before># Buddy

Your friendly BDD testing library for Haxe!

## Quickstart

1) Install the lib:

`haxelib install buddy`

2) Create a test file:

**Main.hx**

```haxe
package ;
import buddy.*;
using buddy.Should;

// "implements Buddy" is only required for the Main class.
class Main extends BuddySuite implements Buddy {
    public function new() {
        // A test suite:
        describe("Using Buddy", {
            var experience = "?";
            var mood = "?";

            // Executed before each "it":
            before({
                experience = "great";
            });

            it("should be a great testing experience", {
                experience.should.be("great");
            });

            it("should really make the tester happy", {
                mood.should.be("happy");
            });

            // Executed after each "it":
            after({
                mood = "happy";
            });
        });
    }
}
```

3) Make a quick test:

`haxe -lib buddy -main Main --interp`

```
..
Using Buddy
  should be a great testing experience (Passed)
  should really make the tester happy (Passed)
2 specs, 0 failures, 0 pending
```

But of course you shouldn't stop there. Try using it on other targets than Neko, Buddy supports them all on both Windows and Linux! The only thing you need to remember is to add `-D nodejs` if you're targeting Node.js, and `-D HXCPP_M64` if you're targeting C++ on a 64bit platform (that one seems to vary between Linux and Win though).

## Asynchronous support

Buddy was built from the ground up to have great support for async testing, so it's fully compatible with Node.js and handles ajax requests with ease. To use it, just create the specification with a function that takes one argument (targeting javascript now):

```haxe
package ;
import buddy.*;
using buddy.Should;

class AsyncTest extends BuddySuite implements Buddy {
    public function new() {
        describe("Using Buddy asynchronously", {
            var mood = "?";

            // Add function(done) here to enable async testing:
            before(function(done) {
                haxe.Timer.delay(function() {
                    mood = "thrilled";
                    done(); // Call the done() function when the async operation is complete.
                }, 100);
            });

			// Can be added to "it" and "after" as well if needed.
            it("cannot really be described in one sentence", {
                mood.should.be("thrilled");
            });
        });
    }
}
```

The default timeout is 5000 ms, after which the spec will automatically fail if `done()` hasn't been called. If you want to change the timeout, set the property `timeoutMs` in the `BuddySuite` **before** the actual `it()` specification, or in the before/after block. Here's an example:

```haxe
package ;
import buddy.*;
using buddy.Should;

class AsyncTest extends BuddySuite implements Buddy {
    public function new() {
        describe("Using Buddy asynchronously", {
            this.timeoutMs = 100;
            it("should fail specs after a timeout set before it()", function(done) {
                // This test will fail after 100 ms.
                haxe.Timer.delay(done, 200);
            });
        });
    }
}
```

## Should assertions

As you've seen in the examples, testing if the specifications are correct is as simple as adding `using Buddy.should` to the package and then use the `should` extension for the identifier you want to test. The following assertions are supported:

### All types

`a.should.be(b)` - Tests for equality for value types (`Bool`, `Float`, `Int`) and identity for the other (reference) types.

### Int

`a.should.beLessThan(b)`

`a.should.beGreaterThan(b)`

### Float

Same as Int plus<commit_msg>Added string to equality tests in docs [skip ci]<commit_after># Buddy

Your friendly BDD testing library for Haxe!

## Quickstart

1) Install the lib:

`haxelib install buddy`

2) Create a test file:

**Main.hx**

```haxe
package ;
import buddy.*;
using buddy.Should;

// "implements Buddy" is only required for the Main class.
class Main extends BuddySuite implements Buddy {
    public function new() {
        // A test suite:
        describe("Using Buddy", {
            var experience = "?";
            var mood = "?";

            // Executed before each "it":
            before({
                experience = "great";
            });

            it("should be a great testing experience", {
                experience.should.be("great");
            });

            it("should really make the tester happy", {
                mood.should.be("happy");
            });

            // Executed after each "it":
            after({
                mood = "happy";
            });
        });
    }
}
```

3) Make a quick test:

`haxe -lib buddy -main Main --interp`

```
..
Using Buddy
  should be a great testing experience (Passed)
  should really make the tester happy (Passed)
2 specs, 0 failures, 0 pending
```

But of course you shouldn't stop there. Try using it on other targets than Neko, Buddy supports them all on both Windows and Linux! The only thing you need to remember is to add `-D nodejs` if you're targeting Node.js, and `-D HXCPP_M64` if you're targeting C++ on a 64bit platform (that one seems to vary between Linux and Win though).

## Asynchronous support

Buddy was built from the ground up to have great support for async testing, so it's fully compatible with Node.js and handles ajax requests with ease. To use it, just create the specification with a function that takes one argument (targeting javascript now):

```haxe
package ;
import buddy.*;
using buddy.Should;

class AsyncTest extends BuddySuite implements Buddy {
    public function new() {
        describe("Using Buddy asynchronously", {
            var mood = "?";

            // Add function(done) here to enable async testing:
            before(function(done) {
                haxe.Timer.delay(function() {
                    mood = "thrilled";
                    done(); // Call the done() function when the async operation is complete.
                }, 100);
            });

			// Can be added to "it" and "after" as well if needed.
            it("cannot really be described in one sentence", {
                mood.should.be("thrilled");
            });
        });
    }
}
```

The default timeout is 5000 ms, after which the spec will automatically fail if `done()` hasn't been called. If you want to change the timeout, set the property `timeoutMs` in the `BuddySuite` **before** the actual `it()` specification, or in the before/after block. Here's an example:

```haxe
package ;
import buddy.*;
using buddy.Should;

class AsyncTest extends BuddySuite implements Buddy {
    public function new() {
        describe("Using Buddy asynchronously", {
            this.timeoutMs = 100;
            it("should fail specs after a timeout set before it()", function(done) {
                // This test will fail after 100 ms.
                haxe.Timer.delay(done, 200);
            });
        });
    }
}
```

## Should assertions

As you've seen in the examples, testing if the specifications are correct is as simple as adding `using Buddy.should` to the package and then use the `should` extension for the identifier you want to test. The following assertions are supported:

### All types

`a.should.be(b)` - Tests equality for value types (`Bool`, `Float`, `Int` and the special `String`) and identity for the other (reference) types.

### Int

`a.should.beLessThan(b)`

`a.should.beGreaterThan(b)`

### Float

Same as Int plus
{'fraction_non_alphanumeric': 0.10138852501964894, 'fraction_numerical': 0.006811632171862719, 'mean_word_length': 2.3783185840707963, 'pattern_counts': {'":': 4, '<': 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': '3446098', 'n_tokens_mistral': 2170, 'n_tokens_neox': 2012, 'n_words': 886}