Skip to content

Commit

Permalink
Merge pull request #660 from Kenny2github/patch-1
Browse files Browse the repository at this point in the history
Add [string] contains [string] block
  • Loading branch information
thisandagain committed Aug 10, 2017
2 parents 3beebdc + 884e24f commit 6988571
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/blocks/scratch3_operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Scratch3OperatorsBlocks {
operator_join: this.join,
operator_letter_of: this.letterOf,
operator_length: this.length,
operator_contains: this.contains,
operator_mod: this.mod,
operator_round: this.round,
operator_mathop: this.mathop
Expand Down Expand Up @@ -106,6 +107,13 @@ class Scratch3OperatorsBlocks {
length (args) {
return Cast.toString(args.STRING).length;
}

contains (args) {
const format = function (string) {
return Cast.toString(string).toLowerCase();
};
return format(args.STRING1).includes(format(args.STRING2));
}

mod (args) {
const n = Cast.toNumber(args.NUM1);
Expand Down
7 changes: 7 additions & 0 deletions test/unit/blocks_operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ test('length', t => {
t.end();
});

test('contains', t => {
t.strictEqual(blocks.contains({STRING1: 'hello world', STRING2: 'hello'}), true);
t.strictEqual(blocks.contains({STRING1: 'foo', STRING2: 'bar'}), false);
t.strictEqual(blocks.contains({STRING1: 'HeLLo world', STRING2: 'hello'}), true);
t.end();
});

test('mod', t => {
t.strictEqual(blocks.mod({NUM1: 1, NUM2: 1}), 0);
t.strictEqual(blocks.mod({NUM1: 3, NUM2: 6}), 3);
Expand Down

0 comments on commit 6988571

Please sign in to comment.