@@ -897,6 +897,123 @@ void main() {
897897 });
898898 });
899899
900+ group ('YouTube Errors' , () {
901+ Class documentationErrors;
902+ Method withYouTubeWrongParams;
903+ Method withYouTubeBadWidth;
904+ Method withYouTubeBadHeight;
905+ Method withYouTubeInvalidUrl;
906+ Method withYouTubeUrlWithAdditionalParameters;
907+
908+ setUpAll (() {
909+ documentationErrors = errorLibrary.classes
910+ .firstWhere ((c) => c.name == 'DocumentationErrors' )
911+ ..documentation;
912+ withYouTubeWrongParams = documentationErrors.allInstanceMethods
913+ .firstWhere ((m) => m.name == 'withYouTubeWrongParams' )
914+ ..documentation;
915+ withYouTubeBadWidth = documentationErrors.allInstanceMethods
916+ .firstWhere ((m) => m.name == 'withYouTubeBadWidth' )
917+ ..documentation;
918+ withYouTubeBadHeight = documentationErrors.allInstanceMethods
919+ .firstWhere ((m) => m.name == 'withYouTubeBadHeight' )
920+ ..documentation;
921+ withYouTubeInvalidUrl = documentationErrors.allInstanceMethods
922+ .firstWhere ((m) => m.name == 'withYouTubeInvalidUrl' )
923+ ..documentation;
924+ withYouTubeUrlWithAdditionalParameters = documentationErrors.allInstanceMethods
925+ .firstWhere ((m) => m.name == 'withYouTubeUrlWithAdditionalParameters' )
926+ ..documentation;
927+ });
928+
929+ test ("warns on youtube video with missing parameters" , () {
930+ expect (
931+ packageGraphErrors.packageWarningCounter.hasWarning (
932+ withYouTubeWrongParams,
933+ PackageWarning .invalidParameter,
934+ 'Invalid @youtube directive, "{@youtube https://youtu.be/oHg5SJYRHA0}"\n '
935+ 'YouTube directives must be of the form "{@youtube WIDTH HEIGHT URL}"' ),
936+ isTrue);
937+ });
938+ test ("warns on youtube video with non-integer width" , () {
939+ expect (
940+ packageGraphErrors.packageWarningCounter.hasWarning (
941+ withYouTubeBadWidth,
942+ PackageWarning .invalidParameter,
943+ 'A @youtube directive has an invalid width, "100px". The width '
944+ 'must be a positive integer.' ),
945+ isTrue);
946+ });
947+ test ("warns on youtube video with non-integer height" , () {
948+ expect (
949+ packageGraphErrors.packageWarningCounter.hasWarning (
950+ withYouTubeBadHeight,
951+ PackageWarning .invalidParameter,
952+ 'A @youtube directive has an invalid height, "100px". The height '
953+ 'must be a positive integer.' ),
954+ isTrue);
955+ });
956+ test ("warns on youtube video with invalid video URL" , () {
957+ expect (
958+ packageGraphErrors.packageWarningCounter.hasWarning (
959+ withYouTubeInvalidUrl,
960+ PackageWarning .invalidParameter,
961+ 'A @youtube directive has an invalid URL: '
962+ '"http://host/path/to/video.mp4". Supported YouTube URLs have '
963+ 'the follwing format: '
964+ 'https://www.youtube.com/watch?v=oHg5SJYRHA0.' ),
965+ isTrue);
966+ });
967+ test ("warns on youtube video with extra parameters in URL" , () {
968+ expect (
969+ packageGraphErrors.packageWarningCounter.hasWarning (
970+ withYouTubeUrlWithAdditionalParameters,
971+ PackageWarning .invalidParameter,
972+ 'A @youtube directive has an invalid URL: '
973+ '"https://www.youtube.com/watch?v=yI-8QHpGIP4&list=PLjxrf2q8roU23XGwz3Km7sQZFTdB996iG&index=5". '
974+ 'Supported YouTube URLs have the follwing format: '
975+ 'https://www.youtube.com/watch?v=oHg5SJYRHA0.' ),
976+ isTrue);
977+ });
978+ });
979+
980+ group ('YouTube' , () {
981+ Class dog;
982+ Method withYouTubeWatchUrl;
983+ Method withYouTubeInOneLineDoc;
984+ Method withYouTubeInline;
985+
986+ setUpAll (() {
987+ dog = exLibrary.classes.firstWhere ((c) => c.name == 'Dog' );
988+ withYouTubeWatchUrl = dog.allInstanceMethods
989+ .firstWhere ((m) => m.name == 'withYouTubeWatchUrl' );
990+ withYouTubeInOneLineDoc = dog.allInstanceMethods
991+ .firstWhere ((m) => m.name == 'withYouTubeInOneLineDoc' );
992+ withYouTubeInline = dog.allInstanceMethods
993+ .firstWhere ((m) => m.name == 'withYouTubeInline' );
994+ });
995+
996+ test ("renders a YouTube video within the method documentation with correct aspect ratio" , () {
997+ expect (withYouTubeWatchUrl.documentation,
998+ contains ('<iframe src="https://www.youtube.com/embed/oHg5SJYRHA0?rel=0"' ));
999+ // Video is 560x315, which means height is 56.25% of width.
1000+ expect (withYouTubeWatchUrl.documentation, contains ('padding-top: 56.25%;' ));
1001+ });
1002+ test ("Doesn't place YouTube video in one line doc" , () {
1003+ expect (
1004+ withYouTubeInOneLineDoc.oneLineDoc,
1005+ isNot (contains (
1006+ '<iframe src="https://www.youtube.com/embed/oHg5SJYRHA0?rel=0"' )));
1007+ expect (withYouTubeInOneLineDoc.documentation,
1008+ contains ('<iframe src="https://www.youtube.com/embed/oHg5SJYRHA0?rel=0"' ));
1009+ });
1010+ test ("Handles YouTube video inline properly" , () {
1011+ // Make sure it doesn't have a double-space before the continued line,
1012+ // which would indicate to Markdown to indent the line.
1013+ expect (withYouTubeInline.documentation, isNot (contains (' works' )));
1014+ });
1015+ });
1016+
9001017 group ('Animation Errors' , () {
9011018 Class documentationErrors;
9021019 Method withInvalidNamedAnimation;
@@ -1790,7 +1907,7 @@ void main() {
17901907 });
17911908
17921909 test ('get methods' , () {
1793- expect (Dog .publicInstanceMethods, hasLength (19 ));
1910+ expect (Dog .publicInstanceMethods, hasLength (22 ));
17941911 });
17951912
17961913 test ('get operators' , () {
@@ -1865,7 +1982,10 @@ void main() {
18651982 'withNamedAnimation' ,
18661983 'withPrivateMacro' ,
18671984 'withQuotedNamedAnimation' ,
1868- 'withUndefinedMacro'
1985+ 'withUndefinedMacro' ,
1986+ 'withYouTubeInline' ,
1987+ 'withYouTubeInOneLineDoc' ,
1988+ 'withYouTubeWatchUrl' ,
18691989 ]));
18701990 });
18711991
0 commit comments