• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FontoXML / fontoxpath / 6107185957

07 Sep 2023 08:15AM UTC coverage: 91.555%. Remained the same
6107185957

push

github

DrRataplan
3.30.1

4938 of 5738 branches covered (0.0%)

Branch coverage included in aggregate %.

10640 of 11277 relevant lines covered (94.35%)

97908.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.92
/src/expressions/dataTypes/Sequences/ArrayBackedSequence.ts
1
import { errFORG0006 } from '../../functions/FunctionOperationErrors';
9✔
2
import { DONE_TOKEN, IIterator, ready } from '../../util/iterators';
9✔
3
import ISequence, { SwitchCasesCases } from '../ISequence';
4
import isSubtypeOf from '../isSubtypeOf';
9✔
5
import sequenceFactory from '../sequenceFactory';
6
import Value, { ValueType } from '../Value';
7

8
export default class ArrayBackedSequence implements ISequence {
9✔
9
        public value: IIterator<Value>;
10

11
        constructor(
12
                private readonly _sequenceFactory: typeof sequenceFactory,
54,114✔
13
                private readonly _values: Value[]
54,114✔
14
        ) {
15
                let i = -1;
54,114✔
16
                this.value = {
54,114✔
17
                        next: () => {
18
                                i++;
196,416✔
19
                                if (i >= _values.length) {
196,416✔
20
                                        return DONE_TOKEN;
53,460✔
21
                                }
22
                                return ready(_values[i]);
142,956✔
23
                        },
24
                };
25
        }
26

27
        public expandSequence(): ISequence {
28
                return this;
×
29
        }
30

31
        public filter(callback: (value: Value, i: number, sequence: ISequence) => boolean): ISequence {
32
                let i = -1;
×
33
                return this._sequenceFactory.create({
×
34
                        next: () => {
35
                                i++;
×
36
                                while (i < this._values.length && !callback(this._values[i], i, this)) {
×
37
                                        i++;
×
38
                                }
39

40
                                if (i >= this._values.length) {
×
41
                                        return DONE_TOKEN;
×
42
                                }
43

44
                                return ready(this._values[i]);
×
45
                        },
46
                });
47
        }
48

49
        public first(): Value | null {
50
                return this._values[0];
18✔
51
        }
52

53
        public getAllValues(): Value[] {
54
                return this._values;
9✔
55
        }
56

57
        public getEffectiveBooleanValue(): boolean {
58
                if (isSubtypeOf(this._values[0].type, ValueType.NODE)) {
×
59
                        return true;
×
60
                }
61
                // We always have a length > 1, or we'd be a singletonSequence
62
                throw errFORG0006(
×
63
                        `Cannot determine the effective boolean value of a sequence with a length higher than one.`
64
                );
65
        }
66

67
        public getLength(): number {
68
                return this._values.length;
15✔
69
        }
70

71
        public isEmpty(): boolean {
72
                return false;
6✔
73
        }
74

75
        public isSingleton(): boolean {
76
                return false;
6✔
77
        }
78

79
        public map(callback: (value: Value, i: number, sequence: ISequence) => Value): ISequence {
80
                let i = -1;
381✔
81
                return this._sequenceFactory.create(
381✔
82
                        {
83
                                next: () => {
84
                                        return ++i >= this._values.length
1,461!
85
                                                ? DONE_TOKEN
86
                                                : ready(callback(this._values[i], i, this));
87
                                },
88
                        },
89
                        this._values.length
90
                );
91
        }
92

93
        public mapAll(callback: (allValues: Value[]) => ISequence): ISequence {
94
                return callback(this._values);
×
95
        }
96

97
        public switchCases(cases: SwitchCasesCases): ISequence {
98
                if (cases.multiple) {
×
99
                        return cases.multiple(this);
×
100
                }
101
                return cases.default(this);
×
102
        }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc