-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tdp,gen): implement basic pretty print
- Loading branch information
Showing
7 changed files
with
169 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dcOption#18b7a10d flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption; | ||
config#330b4067 flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true pfs_enabled:flags.13?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector<DcOption> dc_txt_domain_name:string chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int pinned_infolder_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string autoupdate_url_prefix:flags.7?string gif_search_username:flags.9?string venue_search_username:flags.10?string img_search_username:flags.11?string static_maps_provider:flags.12?string caption_length_max:int message_length_max:int webfile_dc_id:int suggested_lang_code:flags.2?string lang_pack_version:flags.2?int base_lang_pack_version:flags.2?int = Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package internal | ||
|
||
//go:generate go run github.com/gotd/td/cmd/gotdgen --format=true --clean --package schema --target schema --schema _testdata/schema.tl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
package tdp | ||
package tdp_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/gotd/td/tdp" | ||
"github.com/gotd/td/tdp/internal/schema" | ||
) | ||
|
||
func TestFormat(t *testing.T) { | ||
for _, tt := range []struct { | ||
Input interface{} | ||
Output string | ||
Input tdp.Object | ||
Output string | ||
Options []tdp.Option | ||
}{ | ||
{Output: "<nil>"}, | ||
{ | ||
Output: "<nil>", | ||
}, | ||
{ | ||
Input: &schema.DcOption{ | ||
ID: 10, | ||
IPAddress: "127.0.0.1", | ||
Port: 1010, | ||
}, | ||
Options: []tdp.Option{tdp.WithTypeID}, | ||
Output: "dcOption#18b7a10d", | ||
}, | ||
|
||
{ | ||
Input: &schema.Config{ | ||
DCOptions: []schema.DcOption{ | ||
{ | ||
ID: 1, | ||
IPAddress: "127.0.0.1", | ||
Port: 1010, | ||
}, | ||
}, | ||
}, | ||
Options: []tdp.Option{tdp.WithTypeID}, | ||
}, | ||
} { | ||
t.Skip("TODO: Use golden files") | ||
t.Run(tt.Output, func(t *testing.T) { | ||
require.Equal(t, tt.Output, Format(tt.Input)) | ||
require.Equal(t, tt.Output, tdp.Format(tt.Input, tt.Options...)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package tdp | ||
|
||
// Field of TL type, non-recursive. | ||
type Field struct { | ||
Name string | ||
SchemaName string | ||
Null bool | ||
} | ||
|
||
// Type info for TL type, non-recursive. | ||
type Type struct { | ||
// Name in TL schema. | ||
Name string | ||
// ID is type id. | ||
ID int | ||
// Fields of type. | ||
Fields []Field | ||
// Null denotes whether value is null. | ||
Null bool | ||
} | ||
|
||
// Object of TL schema that can return type info. | ||
type Object interface { | ||
TypeInfo() Type | ||
} |