@@ -377,6 +377,65 @@ func TestConvertTwitchLiveChatToTDLChatDoesNotReplaceOutputOnInvalidInput(t *tes
377377 }
378378}
379379
380+ func TestConvertLiveCommentToTDLCommentRejectsMalformedEmoteLocations (t * testing.T ) {
381+ chatStart := time .Unix (1_700_000_000 , 0 )
382+
383+ for _ , location := range []string {"" , "missing-delimiter" } {
384+ t .Run (location , func (t * testing.T ) {
385+ comment := LiveComment {
386+ Message : "Kappa" ,
387+ MessageID : "message-id" ,
388+ Timestamp : chatStart .UnixMicro (),
389+ Emotes : []LiveCommentEmote {
390+ {
391+ Name : "Kappa" ,
392+ Locations : []string {location },
393+ },
394+ },
395+ }
396+
397+ if _ , _ , err := convertLiveCommentToTDLComment (comment , chatStart ); err == nil {
398+ t .Fatalf ("expected malformed emote location %q to return an error" , location )
399+ }
400+ })
401+ }
402+ }
403+
404+ func TestConvertLiveCommentToTDLCommentSkipsOverlappingEmoteFragments (t * testing.T ) {
405+ chatStart := time .Unix (1_700_000_000 , 0 )
406+ comment := LiveComment {
407+ Message : "Kappa" ,
408+ MessageID : "message-id" ,
409+ Timestamp : chatStart .UnixMicro (),
410+ Emotes : []LiveCommentEmote {
411+ {
412+ ID : "first-emote" ,
413+ Name : "Kappa" ,
414+ Locations : []string {"0-4" },
415+ },
416+ {
417+ ID : "overlapping-emote" ,
418+ Name : "appa" ,
419+ Locations : []string {"1-4" },
420+ },
421+ },
422+ }
423+
424+ converted , include , err := convertLiveCommentToTDLComment (comment , chatStart )
425+ if err != nil {
426+ t .Fatalf ("expected overlapping emote to be skipped, got error: %v" , err )
427+ }
428+ if ! include {
429+ t .Fatal ("expected comment to be included" )
430+ }
431+
432+ for _ , fragment := range converted .Message .Fragments {
433+ if fragment .Emoticon != nil && fragment .Emoticon .EmoticonID == "overlapping-emote" {
434+ t .Fatalf ("expected overlapping emote fragment to be skipped, got %#v" , converted .Message .Fragments )
435+ }
436+ }
437+ }
438+
380439func TestEnrichTwitchChatMetadataFromLiveChat (t * testing.T ) {
381440 tmpDir := t .TempDir ()
382441 liveChatPath := filepath .Join (tmpDir , "live-chat.json" )
0 commit comments