From 2e9b62dfda4881eff8fbdcd11a3a60176bcc4648 Mon Sep 17 00:00:00 2001 From: delphinus Date: Sun, 26 Nov 2017 17:29:58 +0900 Subject: [PATCH 1/4] Use subtest feature to show test titles in log --- all_test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/all_test.go b/all_test.go index fb0cf05..9215061 100644 --- a/all_test.go +++ b/all_test.go @@ -561,18 +561,20 @@ func beautify(ua *UserAgent) (s string) { // The test suite. func TestUserAgent(t *testing.T) { for _, tt := range uastrings { - ua := New(tt.ua) - got := beautify(ua) - if tt.expected != got { - t.Errorf("\nTest %v\ngot: %q\nexpected %q\n", tt.title, got, tt.expected) - } + t.Run(tt.title, func(t *testing.T) { + ua := New(tt.ua) + got := beautify(ua) + if tt.expected != got { + t.Errorf("\nTest %v\ngot: %q\nexpected %q\n", tt.title, got, tt.expected) + } - if tt.expectedOS != nil { - gotOSInfo := ua.OSInfo() - if !reflect.DeepEqual(tt.expectedOS, &gotOSInfo) { - t.Errorf("\nTest %v\ngot: %#v\nexpected %#v\n", tt.title, gotOSInfo, tt.expectedOS) + if tt.expectedOS != nil { + gotOSInfo := ua.OSInfo() + if !reflect.DeepEqual(tt.expectedOS, &gotOSInfo) { + t.Errorf("\nTest %v\ngot: %#v\nexpected %#v\n", tt.title, gotOSInfo, tt.expectedOS) + } } - } + }) } } From 77dbfbeaa7d3fd12d4574a2985ce3c71c8e1c849 Mon Sep 17 00:00:00 2001 From: delphinus Date: Sun, 26 Nov 2017 17:33:35 +0900 Subject: [PATCH 2/4] Detect Googlebot like Android --- all_test.go | 7 ++++++- operating_systems.go | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/all_test.go b/all_test.go index 9215061..4643cf9 100644 --- a/all_test.go +++ b/all_test.go @@ -25,10 +25,15 @@ var uastrings = []struct { expected: "Mozilla:5.0 Browser:Googlebot-2.1 Bot:true Mobile:false", }, { - title: "GoogleBotSmartphone", + title: "GoogleBotSmartphone (iPhone)", ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", expected: "Mozilla:5.0 Browser:Googlebot-2.1 Bot:true Mobile:true", }, + { + title: "GoogleBotSmartphone (Android)", + ua: "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", + expected: "Mozilla:5.0 Browser:Googlebot-2.1 Bot:true Mobile:true", + }, { title: "BingBot", ua: "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", diff --git a/operating_systems.go b/operating_systems.go index aebd8b3..0a08b9c 100644 --- a/operating_systems.go +++ b/operating_systems.go @@ -89,6 +89,9 @@ func webkit(p *UserAgent, comment []string) { if len(comment) > 3 { p.localization = comment[3] } + if len(comment) == 3 { + _ = p.googleBot() + } } else if len(comment) > 0 { if len(comment) > 3 { p.localization = comment[3] From edb5c17fc5816d71144ecaa5ea7c2d4ba1cecd52 Mon Sep 17 00:00:00 2001 From: delphinus Date: Sun, 26 Nov 2017 18:00:46 +0900 Subject: [PATCH 3/4] Revert "Use subtest feature to show test titles in log" This reverts commit 2e9b62dfda4881eff8fbdcd11a3a60176bcc4648. --- all_test.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/all_test.go b/all_test.go index 4643cf9..51c761b 100644 --- a/all_test.go +++ b/all_test.go @@ -566,20 +566,18 @@ func beautify(ua *UserAgent) (s string) { // The test suite. func TestUserAgent(t *testing.T) { for _, tt := range uastrings { - t.Run(tt.title, func(t *testing.T) { - ua := New(tt.ua) - got := beautify(ua) - if tt.expected != got { - t.Errorf("\nTest %v\ngot: %q\nexpected %q\n", tt.title, got, tt.expected) - } + ua := New(tt.ua) + got := beautify(ua) + if tt.expected != got { + t.Errorf("\nTest %v\ngot: %q\nexpected %q\n", tt.title, got, tt.expected) + } - if tt.expectedOS != nil { - gotOSInfo := ua.OSInfo() - if !reflect.DeepEqual(tt.expectedOS, &gotOSInfo) { - t.Errorf("\nTest %v\ngot: %#v\nexpected %#v\n", tt.title, gotOSInfo, tt.expectedOS) - } + if tt.expectedOS != nil { + gotOSInfo := ua.OSInfo() + if !reflect.DeepEqual(tt.expectedOS, &gotOSInfo) { + t.Errorf("\nTest %v\ngot: %#v\nexpected %#v\n", tt.title, gotOSInfo, tt.expectedOS) } - }) + } } } From e6cee85e1330bf4b476f5a40bd3e8f7269999fe8 Mon Sep 17 00:00:00 2001 From: delphinus Date: Thu, 30 Nov 2017 22:50:08 +0900 Subject: [PATCH 4/4] Use `else if` to reduce blocks --- operating_systems.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/operating_systems.go b/operating_systems.go index 0a08b9c..329f8ab 100644 --- a/operating_systems.go +++ b/operating_systems.go @@ -88,8 +88,7 @@ func webkit(p *UserAgent, comment []string) { } if len(comment) > 3 { p.localization = comment[3] - } - if len(comment) == 3 { + } else if len(comment) == 3 { _ = p.googleBot() } } else if len(comment) > 0 {