@woosh/meep-engine 2.48.10 → 2.48.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.48.10",
8
+ "version": "2.48.12",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -589,7 +589,7 @@ export class HashMap {
589
589
  } else {
590
590
  return {
591
591
  done: false,
592
- value: n.value[0]
592
+ value: n.value[1]
593
593
  };
594
594
  }
595
595
 
@@ -616,7 +616,7 @@ export class HashMap {
616
616
  } else {
617
617
  return {
618
618
  done: false,
619
- value: n.value[1]
619
+ value: n.value[0]
620
620
  };
621
621
  }
622
622
 
@@ -1,5 +1,5 @@
1
1
  import { HashMap } from "./HashMap.js";
2
- import { passThrough, strictEquals } from "../function/Functions.js";
2
+ import { passThrough, returnOne, strictEquals } from "../function/Functions.js";
3
3
 
4
4
  /**
5
5
  *
@@ -74,3 +74,26 @@ test("retrieval works as intended after hash map grows", () => {
74
74
  expect(m.get(-7)).toEqual("c");
75
75
 
76
76
  });
77
+
78
+
79
+ test("key iterator", () => {
80
+ const map = new HashMap({
81
+ keyHashFunction: returnOne,
82
+ keyEqualityFunction: strictEquals
83
+ });
84
+
85
+ map.set(7, "hello");
86
+
87
+ expect(map.keys().next().value).toBe(7);
88
+ });
89
+
90
+ test("value iterator", () => {
91
+ const map = new HashMap({
92
+ keyHashFunction: returnOne,
93
+ keyEqualityFunction: strictEquals
94
+ });
95
+
96
+ map.set(7, "hello");
97
+
98
+ expect(map.values().next().value).toBe("hello");
99
+ });
@@ -0,0 +1,63 @@
1
+ import { BaseMatcher } from "../BaseMatcher.js";
2
+
3
+
4
+ const RX = /%([0-9]+)/gi;
5
+
6
+ export class DescribeAs extends BaseMatcher {
7
+ /**
8
+ * @type {string}
9
+ */
10
+ template
11
+ /**
12
+ * @type {Matcher}
13
+ */
14
+ matcher
15
+ /**
16
+ * @type {[]}
17
+ */
18
+ values
19
+
20
+ /**
21
+ *
22
+ * @param {string} template
23
+ * @param {Matcher} matcher
24
+ * @param {[]} values
25
+ */
26
+ constructor(template, matcher, values) {
27
+ super();
28
+
29
+ this.template = template;
30
+ this.matcher = matcher;
31
+ this.values = values;
32
+ }
33
+
34
+ matches(item, mismatch_description) {
35
+ return this.matcher.matches(item, mismatch_description);
36
+ }
37
+
38
+ describeTo(description) {
39
+
40
+ let textStart = 0;
41
+
42
+ const matches = this.template.matchAll(RX);
43
+
44
+ for (let i = 0; i < matches.length; i++) {
45
+ const match = matches[i];
46
+
47
+ description.appendText(this.template.substring(textStart, match.index));
48
+
49
+ const group_index = parseInt(match.groups[1]);
50
+
51
+ description.appendValue(this.values[group_index]);
52
+
53
+ textStart = match[0].length;
54
+ }
55
+ if (textStart < this.template.length) {
56
+ description.appendText(this.template.slice(textStart));
57
+ }
58
+ }
59
+
60
+ describeMismatch(item, mismatch_description) {
61
+ this.matcher.describeMismatch(item, mismatch_description);
62
+ }
63
+ }
@@ -0,0 +1,19 @@
1
+ import { BaseMatcher } from "../BaseMatcher.js";
2
+
3
+ export class IsAnything extends BaseMatcher {
4
+ message
5
+
6
+ constructor(message = "ANYTHING") {
7
+ super();
8
+
9
+ this.message = message;
10
+ }
11
+
12
+ matches(item, mismatch_description = NullDescription.INSTANCE) {
13
+ return false;
14
+ }
15
+
16
+ describeTo(description) {
17
+ description.appendText(this.message);
18
+ }
19
+ }
@@ -7,43 +7,90 @@ import { IsIterableContaining } from "./IsIterableContaining.js";
7
7
  import { Matcher } from "../Matcher.js";
8
8
  import { IsUndefined } from "./IsUndefined.js";
9
9
  import { IsIn } from "./IsIn.js";
10
+ import { IsAnything } from "./IsAnything.js";
11
+ import { DescribeAs } from "./DescribeAs.js";
10
12
 
13
+ /**
14
+ * @template T
15
+ * @param {Matcher<T>} matchers
16
+ * @return {Matcher<T>}
17
+ */
11
18
  export function anyOf(...matchers) {
12
19
  return new AnyOf(matchers);
13
20
  }
14
21
 
22
+ /**
23
+ * @template T
24
+ * @param {Matcher<T>} matchers
25
+ * @return {Matcher<T>}
26
+ */
15
27
  export function allOf(...matchers) {
16
28
  return new AllOf(matchers);
17
29
  }
18
30
 
31
+ /**
32
+ * @template T
33
+ * @param {Matcher<T>} matcher
34
+ * @return {Matcher<T>}
35
+ */
19
36
  export function not(matcher) {
20
37
  return new IsNot(matcher);
21
38
  }
22
39
 
40
+ /**
41
+ * @template T
42
+ * @param {T} thing
43
+ * @return {Matcher<T>}
44
+ */
23
45
  export function equalTo(thing) {
24
46
  return new IsEqual(thing);
25
47
  }
26
48
 
49
+ /**
50
+ * @template T
51
+ * @param {T} thing
52
+ * @return {Matcher<T>}
53
+ */
27
54
  export function notEqualTo(thing) {
28
55
  return not(equalTo(thing));
29
56
  }
30
57
 
58
+ /**
59
+ * @template T
60
+ * @return {Matcher<T>}
61
+ */
31
62
  export function isNull() {
32
63
  return new IsNull();
33
64
  }
34
65
 
66
+ /**
67
+ * @template T
68
+ * @return {Matcher<T>}
69
+ */
35
70
  export function isNotNull() {
36
71
  return not(isNull());
37
72
  }
38
73
 
74
+ /**
75
+ * @template T
76
+ * @return {Matcher<T>}
77
+ */
39
78
  export function isUndefined() {
40
79
  return new IsUndefined();
41
80
  }
42
81
 
82
+ /**
83
+ * @template T
84
+ * @return {Matcher<T>}
85
+ */
43
86
  export function isDefined() {
44
87
  return not(isUndefined());
45
88
  }
46
89
 
90
+ /**
91
+ * @template T
92
+ * @return {Matcher<T>}
93
+ */
47
94
  export const isNoUndefined = isDefined;
48
95
 
49
96
  /**
@@ -77,3 +124,41 @@ export function isIn(array) {
77
124
  export function isOneOf(...elements) {
78
125
  return isIn(elements);
79
126
  }
127
+
128
+
129
+ /**
130
+ * @template T
131
+ * @param {string} template
132
+ * @param {Matcher<T>} matcher
133
+ * @param {[]} values
134
+ * @returns {Matcher<T>}
135
+ */
136
+ function describeAs(template, matcher, values) {
137
+ return new DescribeAs(template, matcher, values);
138
+ }
139
+
140
+ /**
141
+ *
142
+ * @template T
143
+ * @param {string} [message]
144
+ * @return {Matcher<T>}
145
+ */
146
+ export function anything(message) {
147
+ return new IsAnything(message);
148
+ }
149
+
150
+ /**
151
+ * @template T
152
+ * @param {string} [message]
153
+ * @return {Matcher<T>}
154
+ */
155
+ export function nothing(message) {
156
+ const matcher = not(anything());
157
+
158
+ if (message !== undefined) {
159
+ return describeAs(message, matcher, []);
160
+ } else {
161
+ return matcher;
162
+ }
163
+ }
164
+