1+ import * as assert from "assert" ;
2+ import * as vscode from "vscode" ;
3+ import GoogleJavaFormatEditProvider from "../../GoogleJavaFormatEditProvider" ;
4+ import GoogleJavaFormatEditService from "../../GoogleJavaFormatEditService" ;
5+ import { IGoogleJavaFormatter } from "../../IGoogleJavaFormatter" ;
6+
7+ // Mock formatter for testing
8+ class MockFormatter implements IGoogleJavaFormatter {
9+ async format (
10+ text : string ,
11+ lines : [ number , number ] ,
12+ signal : AbortSignal ,
13+ ) : Promise < string > {
14+ return text ; // Return text as-is for testing
15+ }
16+ }
17+
18+ suite ( "GoogleJavaFormatEditService Test Suite" , ( ) => {
19+ let context : vscode . ExtensionContext ;
20+ let log : vscode . LogOutputChannel ;
21+ let editProvider : GoogleJavaFormatEditProvider ;
22+ let editService : GoogleJavaFormatEditService ;
23+
24+ suiteSetup ( ( ) => {
25+ // Create mock context and log channel
26+ context = {
27+ subscriptions : [ ] ,
28+ } as any ;
29+
30+ log = {
31+ debug : ( ) => { } ,
32+ info : ( ) => { } ,
33+ error : ( ) => { } ,
34+ } as any ;
35+
36+ const mockFormatter = new MockFormatter ( ) ;
37+ editProvider = new GoogleJavaFormatEditProvider ( mockFormatter , log ) ;
38+ editService = new GoogleJavaFormatEditService (
39+ editProvider ,
40+ context ,
41+ log ,
42+ ) ;
43+ } ) ;
44+
45+ test ( "Should register both DocumentFormattingEditProvider and DocumentRangeFormattingEditProvider" , ( ) => {
46+ // Clear any existing subscriptions
47+ context . subscriptions . length = 0 ;
48+
49+ // Subscribe the edit service
50+ editService . subscribe ( ) ;
51+
52+ // Should have registered two providers
53+ assert . strictEqual (
54+ context . subscriptions . length ,
55+ 2 ,
56+ "Should register exactly 2 formatting providers" ,
57+ ) ;
58+ } ) ;
59+
60+ test ( "EditProvider should implement both required interfaces" , ( ) => {
61+ // Verify that the edit provider implements both required methods
62+ assert . ok (
63+ typeof editProvider . provideDocumentFormattingEdits === "function" ,
64+ "Should implement provideDocumentFormattingEdits method" ,
65+ ) ;
66+ assert . ok (
67+ typeof editProvider . provideDocumentRangeFormattingEdits ===
68+ "function" ,
69+ "Should implement provideDocumentRangeFormattingEdits method" ,
70+ ) ;
71+ } ) ;
72+ } ) ;
0 commit comments