Skip to content

Commit e3d9ed4

Browse files
authored
Merge pull request #39 from grammyjs/feat/workflows
feat: Workflows
2 parents 3df233d + 11be327 commit e3d9ed4

File tree

3 files changed

+67
-27
lines changed

3 files changed

+67
-27
lines changed

.github/workflows/test.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
testType: ["lint", "fmt", "test"]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Deno
21+
uses: denoland/setup-deno@v2
22+
with:
23+
deno-version: v2.x
24+
25+
- name: Run linter
26+
run: deno lint
27+
if: matrix.testType == 'lint'
28+
29+
- name: Check formatting
30+
run: deno fmt --check
31+
if: matrix.testType == 'fmt'
32+
33+
- name: Run tests
34+
run: deno test --allow-import test
35+
if: matrix.testType == 'test'

src/format.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,17 +312,19 @@ export class FormattedString
312312
static linkMessage(text: Stringable, chatId: number, messageId: number) {
313313
return linkMessage(text, chatId, messageId);
314314
}
315-
315+
316316
/**
317317
* Joins an array of formatted strings or plain text into a single FormattedString
318318
* @param items Array of text items to join (can be TextWithEntities, CaptionWithEntities, or string)
319319
* @returns A new FormattedString combining all items
320320
*/
321-
static join(items: (Stringable | TextWithEntities | CaptionWithEntities | string)[]) {
321+
static join(
322+
items: (Stringable | TextWithEntities | CaptionWithEntities | string)[],
323+
) {
322324
if (items.length === 0) {
323325
return new FormattedString("");
324326
}
325-
327+
326328
return items.reduce((acc, item) => {
327329
return fmt`${acc}${item}`;
328330
}, new FormattedString(""));

test/format.test.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -699,72 +699,75 @@ Deno.test("FormattedString - Static join method", () => {
699699
assertInstanceOf(emptyResult, FormattedString);
700700
assertEquals(emptyResult.rawText, "");
701701
assertEquals(emptyResult.rawEntities.length, 0);
702-
702+
703703
// Test array of strings
704704
const stringsResult = FormattedString.join(["Hello", " ", "World"]);
705705
assertInstanceOf(stringsResult, FormattedString);
706706
assertEquals(stringsResult.rawText, "Hello World");
707707
assertEquals(stringsResult.rawEntities.length, 0);
708-
708+
709709
// Test mixed array
710710
const boldText = FormattedString.bold("Bold");
711711
const italicText = FormattedString.italic("Italic");
712712
const plainText = " and ";
713-
713+
714714
const mixedResult = FormattedString.join([
715-
"Start: ",
716-
boldText,
717-
" then ",
718-
italicText,
719-
plainText,
720-
"plain"
715+
"Start: ",
716+
boldText,
717+
" then ",
718+
italicText,
719+
plainText,
720+
"plain",
721721
]);
722-
722+
723723
assertInstanceOf(mixedResult, FormattedString);
724724
assertEquals(mixedResult.rawText, "Start: Bold then Italic and plain");
725-
725+
726726
// Test exact entity count and properties
727727
assertEquals(mixedResult.rawEntities.length, 2);
728-
728+
729729
// Test bold entity
730730
assertEquals(mixedResult.rawEntities[0]?.type, "bold");
731731
assertEquals(mixedResult.rawEntities[0]?.offset, 7); // After "Start: "
732732
assertEquals(mixedResult.rawEntities[0]?.length, 4); // "Bold"
733-
733+
734734
// Test italic entity
735735
assertEquals(mixedResult.rawEntities[1]?.type, "italic");
736736
assertEquals(mixedResult.rawEntities[1]?.offset, 17); // After "Start: Bold then "
737737
assertEquals(mixedResult.rawEntities[1]?.length, 6); // "Italic"
738-
738+
739739
// Test TextWithEntities and CaptionWithEntities
740740
const textWithEntities = {
741741
text: "TextWithEntities",
742-
entities: [{ type: "bold", offset: 0, length: 4 }]
742+
entities: [{ type: "bold", offset: 0, length: 4 }],
743743
};
744-
744+
745745
const captionWithEntities = {
746746
caption: "CaptionWithEntities",
747-
caption_entities: [{ type: "italic", offset: 0, length: 7 }]
747+
caption_entities: [{ type: "italic", offset: 0, length: 7 }],
748748
};
749-
749+
750750
const combinedResult = FormattedString.join([
751751
"Start: ",
752752
textWithEntities,
753753
" and ",
754-
captionWithEntities
754+
captionWithEntities,
755755
]);
756-
756+
757757
assertInstanceOf(combinedResult, FormattedString);
758-
assertEquals(combinedResult.rawText, "Start: TextWithEntities and CaptionWithEntities");
759-
758+
assertEquals(
759+
combinedResult.rawText,
760+
"Start: TextWithEntities and CaptionWithEntities",
761+
);
762+
760763
// Test entity count
761764
assertEquals(combinedResult.rawEntities.length, 2);
762-
765+
763766
// Test first entity from TextWithEntities
764767
assertEquals(combinedResult.rawEntities[0]?.type, "bold");
765768
assertEquals(combinedResult.rawEntities[0]?.offset, 7); // After "Start: "
766769
assertEquals(combinedResult.rawEntities[0]?.length, 4); // "Text" part of "TextWithEntities"
767-
770+
768771
// Test second entity from CaptionWithEntities
769772
assertEquals(combinedResult.rawEntities[1]?.type, "italic");
770773
assertEquals(combinedResult.rawEntities[1]?.offset, 28); // After "Start: TextWithEntities and "

0 commit comments

Comments
 (0)