<commit_before>const enumlib = require('./enum');
const Enum = enumlib.Enum;
const InvalidArgumentException = enumlib.InvalidArgumentException;

test('creating new enum', () => {
    let MyEnum1 = class extends Enum {}.createEnum({1: 'mercury', 3: 'earth', 5: 'saturn'});

    expect(MyEnum1.MERCURY.value).toBe(1);
    expect(MyEnum1.EARTH.value).toBe(3);
    expect(MyEnum1.SATURN.value).toBe(5);

    expect(MyEnum1.MERCURY.name).toBe('mercury');
    expect(MyEnum1.EARTH.name).toBe('earth');
    expect(MyEnum1.SATURN.name).toBe('saturn');

    // may be requires babel to work
    // expect(MyEnum1.name).toBe('MyEnum1');

    let xExtra = {'foo': 'bar'};
    let MyEnum2 = class MyEnum2 extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'}, [xExtra, 10, 'hello']);

    expect(MyEnum2.X.value).toBe(1);
    expect(MyEnum2.Y.value).toBe(2);
    expect(MyEnum2.Z.value).toBe(3);

    expect(MyEnum2.X.name).toBe('x');
    expect(MyEnum2.Y.name).toBe('y');
    expect(MyEnum2.Z.name).toBe('z');

    expect(MyEnum2.X.extra).toBe(xExtra);
    expect(MyEnum2.Y.extra).toBe(10);
    expect(MyEnum2.Z.extra).toBe('hello');
});

test('ensure enums doesn\'t share items', () => {
    let extra1 = {};
    let extra2 = {};
    let MyEnum1 = class extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'}, [extra1, null, null]);
    let MyEnum2 = class extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'}, [extra2, null, null]);

    expect(MyEnum1).not.toBe(MyEnum2);
    expect(MyEnum1.X).not.toBe(MyEnum2.X);
    expect(MyEnum1.X.id).toBe(MyEnum2.X.id);
    expect(MyEnum1.X.name).toBe(MyEnum2.X.name);
    expect(MyEnum1.X.extra).not.toBe(MyEnum2.X.extra);
});

test('ensure enums have expected inheritance', () => {
    let MyEnumA = class extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'});
    let MyEnumBInstance = class extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'});

    // MyEnumA and MyEnumB are just frozen holders of enums, they're not Enums themselves
    expect(MyEnumA).not.toBeInstanceOf(Enum);
    expect(MyEnumBInstance).not.toBeInstanceOf(Enum);

    // But all fields in MyEnumA and MyEnumB are Enum instances
    // You can also do
    //      x = EnumName.KEY;
    //      x instanceof EnumName
    // to ensure that var is a item of EnumName. Or
    //      x instanceof Enum
    // to ensure x is an enum
    Object.keys(MyEnumA).map((key) => {
        expect(MyEnumA[key]).toBeInstanceOf(MyEnumA);<commit_msg>More tests<commit_after>const enumlib = require('./enum');
const Enum = enumlib.Enum;
const InvalidArgumentException = enumlib.InvalidArgumentException;

test('creating new enum', () => {
    let MyEnum1 = class extends Enum {}.createEnum({1: 'mercury', 3: 'earth', 5: 'saturn'});

    expect(MyEnum1.MERCURY.value).toBe(1);
    expect(MyEnum1.EARTH.value).toBe(3);
    expect(MyEnum1.SATURN.value).toBe(5);

    expect(MyEnum1.MERCURY.name).toBe('mercury');
    expect(MyEnum1.EARTH.name).toBe('earth');
    expect(MyEnum1.SATURN.name).toBe('saturn');

    // may be requires babel to work
    // expect(MyEnum1.name).toBe('MyEnum1');

    let xExtra = {'foo': 'bar'};
    let MyEnum2 = class MyEnum2 extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'}, [xExtra, 10, 'hello']);

    expect(MyEnum2.X.value).toBe(1);
    expect(MyEnum2.Y.value).toBe(2);
    expect(MyEnum2.Z.value).toBe(3);

    expect(MyEnum2.X.name).toBe('x');
    expect(MyEnum2.Y.name).toBe('y');
    expect(MyEnum2.Z.name).toBe('z');

    expect(MyEnum2.X.extra).toBe(xExtra);
    expect(MyEnum2.Y.extra).toBe(10);
    expect(MyEnum2.Z.extra).toBe('hello');
});

test('ensure enums doesn\'t share items', () => {
    let extra1 = {};
    let extra2 = {};
    let MyEnum1 = class extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'}, [extra1, null, null]);
    let MyEnum2 = class extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'}, [extra2, null, null]);

    expect(MyEnum1).not.toBe(MyEnum2);
    expect(MyEnum1.X).not.toBe(MyEnum2.X);
    expect(MyEnum1.X.id).toBe(MyEnum2.X.id);
    expect(MyEnum1.X.name).toBe(MyEnum2.X.name);
    expect(MyEnum1.X.extra).not.toBe(MyEnum2.X.extra);

    expect(MyEnum1.X).toBe(MyEnum1.X);
});

test('ensure enums have expected inheritance', () => {
    let MyEnumA = class extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'});
    let MyEnumBInstance = class extends Enum {}.createEnum({1: 'x', 2: 'y', 3: 'z'});

    // MyEnumA and MyEnumB are just frozen holders of enums, they're not Enums themselves
    expect(MyEnumA).not.toBeInstanceOf(Enum);
    expect(MyEnumBInstance).not.toBeInstanceOf(Enum);

    // But all fields in MyEnumA and MyEnumB are Enum instances
    // You can also do
    //      x = EnumName.KEY;
    //      x instanceof EnumName
    // to ensure that var is a item of EnumName. Or
    //      x instanceof Enum
    // to ensure x is an enum
    Object.keys(MyEnumA).map((key) => {
        expect(MyEnumA[key]).toBeInstanceOf(MyEnumA);
{'fraction_non_alphanumeric': 0.18674821610601428, 'fraction_numerical': 0.026503567787971458, 'mean_word_length': 3.513339466421343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1618419', 'n_tokens_mistral': 1833, 'n_tokens_neox': 1771, 'n_words': 377}