fix: Tags -> Anlytics

This commit is contained in:
2023-12-08 11:29:29 +01:00
parent 09c153ba65
commit 3fc2fd9bac
21 changed files with 930 additions and 550 deletions

View File

@ -1,5 +1,5 @@
//
// TagDefinitionTests.swift
// AnalyticsDefinitionTests.swift
//
//
// Created by Loris Perret on 06/12/2023.
@ -10,44 +10,13 @@ import XCTest
@testable import ResgenSwift
final class TagDefinitionTests: XCTestCase {
// MARK: - Match line
func testMatchingTagDefinition() {
// Given
let line = "[definition_name]"
// When
let definition = TagDefinition.match(line)
// Expect
XCTAssertNotNil(definition)
XCTAssertEqual(definition?.title, "definition_name")
}
func testNotMatchingTagDefinition() {
// Given
let line1 = "definition_name"
let line2 = "[definition_name"
let line3 = "definition_name]"
// When
let definition1 = TagDefinition.match(line1)
let definition2 = TagDefinition.match(line2)
let definition3 = TagDefinition.match(line3)
// Expect
XCTAssertNil(definition1)
XCTAssertNil(definition2)
XCTAssertNil(definition3)
}
final class AnalyticsDefinitionTests: XCTestCase {
// MARK: - Matching tags
func testMatchingTags() {
func testMatchingAnalyticss() {
// Given
let definition = TagDefinition(title: "definition_name")
let definition = AnalyticsDefinition(id: "definition_name", name: "", type: .screen)
definition.tags = ["ios","iosonly","notranslation"]
// When
@ -62,9 +31,9 @@ final class TagDefinitionTests: XCTestCase {
XCTAssertTrue(match3)
}
func testNotMatchingTags() {
func testNotMatchingAnalyticss() {
// Given
let definition = TagDefinition(title: "definition_name")
let definition = AnalyticsDefinition(id: "definition_name", name: "", type: .screen)
definition.tags = ["ios","iosonly","notranslation"]
// When
@ -82,10 +51,8 @@ final class TagDefinitionTests: XCTestCase {
func testGeneratedRawPropertyScreen() {
// Given
let definition = TagDefinition(title: "definition_name")
definition.path = "ecran_un/"
definition.name = "Ecran un"
definition.type = "screen"
let definition = AnalyticsDefinition(id: "definition_name", name: "Ecran un", type: .screen)
// When
let propertyScreen = definition.getProperty()
@ -102,10 +69,7 @@ final class TagDefinitionTests: XCTestCase {
func testGeneratedRawPropertyEvent() {
// Given
let definition = TagDefinition(title: "definition_name")
definition.path = "ecran_un/"
definition.name = "Ecran un"
definition.type = "event"
let definition = AnalyticsDefinition(id: "definition_name", name: "Ecran un", type: .screen)
// When
let propertyEvent = definition.getProperty()
@ -122,10 +86,7 @@ final class TagDefinitionTests: XCTestCase {
func testGeneratedRawStaticPropertyScreen() {
// Given
let definition = TagDefinition(title: "definition_name")
definition.path = "ecran_un/"
definition.name = "Ecran un"
definition.type = "screen"
let definition = AnalyticsDefinition(id: "definition_name", name: "Ecran un", type: .screen)
// When
let propertyScreen = definition.getStaticProperty()
@ -142,10 +103,7 @@ final class TagDefinitionTests: XCTestCase {
func testGeneratedRawStaticPropertyEvent() {
// Given
let definition = TagDefinition(title: "definition_name")
definition.path = "ecran_un/"
definition.name = "Ecran un"
definition.type = "event"
let definition = AnalyticsDefinition(id: "definition_name", name: "Ecran un", type: .screen)
// When
let propertyEvent = definition.getStaticProperty()

View File

@ -1,5 +1,5 @@
//
// TagsGeneratorTests.swift
// AnalyticsGeneratorTests.swift
//
//
// Created by Thibaut Schmitt on 06/09/2022.
@ -11,46 +11,43 @@ import ToolCore
@testable import ResgenSwift
final class TagsGeneratorTests: XCTestCase {
final class AnalyticsGeneratorTests: XCTestCase {
private func getTagDefinition(title: String, path: String, name: String, type: String, tags: [String]) -> TagDefinition {
let definition = TagDefinition(title: title)
definition.path = path
definition.name = name
definition.type = type
private func getAnalyticsDefinition(id: String, path: String, name: String, type: AnalyticsDefinition.TagType, tags: [String]) -> AnalyticsDefinition {
let definition = AnalyticsDefinition(id: id, name: name, type: type)
definition.tags = tags
return definition
}
func testGeneratedExtensionContentFirebase() {
// Given
let sectionOne = TagSection(name: "section_one")
let sectionOne = AnalyticsCategory(id: "section_one")
sectionOne.definitions = [
getTagDefinition(title: "s1_def_one", path: "s1_def_one/", name: "s1 def one", type: "screen", tags: ["ios", "iosonly"]),
getTagDefinition(title: "s1_def_two", path: "s1_def_two/", name: "s1 def two", type: "event", tags: ["ios", "iosonly"]),
getAnalyticsDefinition(id: "s1_def_one", path: "s1_def_one/", name: "s1 def one", type: AnalyticsDefinition.TagType.screen, tags: ["ios", "iosonly"]),
getAnalyticsDefinition(id: "s1_def_two", path: "s1_def_two/", name: "s1 def two", type: AnalyticsDefinition.TagType.event, tags: ["ios", "iosonly"]),
]
let sectionTwo = TagSection(name: "section_two")
let sectionTwo = AnalyticsCategory(id: "section_two")
sectionTwo.definitions = [
getTagDefinition(title: "s2_def_one", path: "s2_def_one/", name: "s2 def one", type: "screen", tags: ["ios","iosonly"]),
getTagDefinition(title: "s2_def_two", path: "s2_def_two/", name: "s2 def two", type: "event", tags: ["droid","droidonly"]),
getAnalyticsDefinition(id: "s2_def_one", path: "s2_def_one/", name: "s2 def one", type: AnalyticsDefinition.TagType.screen, tags: ["ios","iosonly"]),
getAnalyticsDefinition(id: "s2_def_two", path: "s2_def_two/", name: "s2 def two", type: AnalyticsDefinition.TagType.event, tags: ["droid","droidonly"]),
]
let sectionThree = TagSection(name: "section_three")
let sectionThree = AnalyticsCategory(id: "section_three")
sectionThree.definitions = [
getTagDefinition(title: "s3_def_one", path: "s3_def_one/", name: "s3 def one", type: "screen", tags: ["droid","droidonly"]),
getTagDefinition(title: "s3_def_two", path: "s3_def_two/", name: "s3 def two", type: "event", tags: ["droid","droidonly"]),
getAnalyticsDefinition(id: "s3_def_one", path: "s3_def_one/", name: "s3 def one", type: AnalyticsDefinition.TagType.screen, tags: ["droid","droidonly"]),
getAnalyticsDefinition(id: "s3_def_two", path: "s3_def_two/", name: "s3 def two", type: AnalyticsDefinition.TagType.event, tags: ["droid","droidonly"]),
]
// When
TagsGenerator.targets = [Tags.TargetType.firebase]
let extensionContent = TagsGenerator.getExtensionContent(sections: [sectionOne, sectionTwo, sectionThree],
AnalyticsGenerator.targets = [Analytics.TargetType.firebase]
let extensionContent = AnalyticsGenerator.getExtensionContent(sections: [sectionOne, sectionTwo, sectionThree],
tags: ["ios", "iosonly"],
staticVar: false,
extensionName: "GenTags")
// Expect Tags
extensionName: "GenAnalytics")
// Expect Analytics
let expect = """
// Generated by ResgenSwift.Tags 1.2
// Generated by ResgenSwift.Analytics 1.2
import UIKit
import Firebase
@ -138,33 +135,33 @@ final class TagsGeneratorTests: XCTestCase {
func testGeneratedExtensionContentMatomo() {
// Given
let sectionOne = TagSection(name: "section_one")
let sectionOne = AnalyticsCategory(id: "section_one")
sectionOne.definitions = [
getTagDefinition(title: "s1_def_one", path: "s1_def_one/", name: "s1 def one", type: "screen", tags: ["ios", "iosonly"]),
getTagDefinition(title: "s1_def_two", path: "s1_def_two/", name: "s1 def two", type: "event", tags: ["ios", "iosonly"]),
getAnalyticsDefinition(id: "s1_def_one", path: "s1_def_one/", name: "s1 def one", type: AnalyticsDefinition.TagType.screen, tags: ["ios", "iosonly"]),
getAnalyticsDefinition(id: "s1_def_two", path: "s1_def_two/", name: "s1 def two", type: AnalyticsDefinition.TagType.event, tags: ["ios", "iosonly"]),
]
let sectionTwo = TagSection(name: "section_two")
let sectionTwo = AnalyticsCategory(id: "section_two")
sectionTwo.definitions = [
getTagDefinition(title: "s2_def_one", path: "s2_def_one/", name: "s2 def one", type: "screen", tags: ["ios","iosonly"]),
getTagDefinition(title: "s2_def_two", path: "s2_def_two/", name: "s2 def two", type: "event", tags: ["droid","droidonly"]),
getAnalyticsDefinition(id: "s2_def_one", path: "s2_def_one/", name: "s2 def one", type: AnalyticsDefinition.TagType.screen, tags: ["ios","iosonly"]),
getAnalyticsDefinition(id: "s2_def_two", path: "s2_def_two/", name: "s2 def two", type: AnalyticsDefinition.TagType.event, tags: ["droid","droidonly"]),
]
let sectionThree = TagSection(name: "section_three")
let sectionThree = AnalyticsCategory(id: "section_three")
sectionThree.definitions = [
getTagDefinition(title: "s3_def_one", path: "s3_def_one/", name: "s3 def one", type: "screen", tags: ["droid","droidonly"]),
getTagDefinition(title: "s3_def_two", path: "s3_def_two/", name: "s3 def two", type: "event", tags: ["droid","droidonly"]),
getAnalyticsDefinition(id: "s3_def_one", path: "s3_def_one/", name: "s3 def one", type: AnalyticsDefinition.TagType.screen, tags: ["droid","droidonly"]),
getAnalyticsDefinition(id: "s3_def_two", path: "s3_def_two/", name: "s3 def two", type: AnalyticsDefinition.TagType.event, tags: ["droid","droidonly"]),
]
// When
TagsGenerator.targets = [Tags.TargetType.matomo]
let extensionContent = TagsGenerator.getExtensionContent(sections: [sectionOne, sectionTwo, sectionThree],
AnalyticsGenerator.targets = [Analytics.TargetType.matomo]
let extensionContent = AnalyticsGenerator.getExtensionContent(sections: [sectionOne, sectionTwo, sectionThree],
tags: ["ios", "iosonly"],
staticVar: false,
extensionName: "GenTags")
// Expect Tags
extensionName: "GenAnalytics")
// Expect Analytics
let expect = """
// Generated by ResgenSwift.Tags 1.2
// Generated by ResgenSwift.Analytics 1.2
import UIKit
import MatomoTracker
@ -287,33 +284,33 @@ final class TagsGeneratorTests: XCTestCase {
func testGeneratedExtensionContentMatomoAndFirebase() {
// Given
let sectionOne = TagSection(name: "section_one")
let sectionOne = AnalyticsCategory(id: "section_one")
sectionOne.definitions = [
getTagDefinition(title: "s1_def_one", path: "s1_def_one/", name: "s1 def one", type: "screen", tags: ["ios", "iosonly"]),
getTagDefinition(title: "s1_def_two", path: "s1_def_two/", name: "s1 def two", type: "event", tags: ["ios", "iosonly"]),
getAnalyticsDefinition(id: "s1_def_one", path: "s1_def_one/", name: "s1 def one", type: AnalyticsDefinition.TagType.screen, tags: ["ios", "iosonly"]),
getAnalyticsDefinition(id: "s1_def_two", path: "s1_def_two/", name: "s1 def two", type: AnalyticsDefinition.TagType.event, tags: ["ios", "iosonly"]),
]
let sectionTwo = TagSection(name: "section_two")
let sectionTwo = AnalyticsCategory(id: "section_two")
sectionTwo.definitions = [
getTagDefinition(title: "s2_def_one", path: "s2_def_one/", name: "s2 def one", type: "screen", tags: ["ios","iosonly"]),
getTagDefinition(title: "s2_def_two", path: "s2_def_two/", name: "s2 def two", type: "event", tags: ["droid","droidonly"]),
getAnalyticsDefinition(id: "s2_def_one", path: "s2_def_one/", name: "s2 def one", type: AnalyticsDefinition.TagType.screen, tags: ["ios","iosonly"]),
getAnalyticsDefinition(id: "s2_def_two", path: "s2_def_two/", name: "s2 def two", type: AnalyticsDefinition.TagType.event, tags: ["droid","droidonly"]),
]
let sectionThree = TagSection(name: "section_three")
let sectionThree = AnalyticsCategory(id: "section_three")
sectionThree.definitions = [
getTagDefinition(title: "s3_def_one", path: "s3_def_one/", name: "s3 def one", type: "screen", tags: ["droid","droidonly"]),
getTagDefinition(title: "s3_def_two", path: "s3_def_two/", name: "s3 def two", type: "event", tags: ["droid","droidonly"]),
getAnalyticsDefinition(id: "s3_def_one", path: "s3_def_one/", name: "s3 def one", type: AnalyticsDefinition.TagType.screen, tags: ["droid","droidonly"]),
getAnalyticsDefinition(id: "s3_def_two", path: "s3_def_two/", name: "s3 def two", type: AnalyticsDefinition.TagType.event, tags: ["droid","droidonly"]),
]
// When
TagsGenerator.targets = [Tags.TargetType.matomo, Tags.TargetType.firebase]
let extensionContent = TagsGenerator.getExtensionContent(sections: [sectionOne, sectionTwo, sectionThree],
AnalyticsGenerator.targets = [Analytics.TargetType.matomo, Analytics.TargetType.firebase]
let extensionContent = AnalyticsGenerator.getExtensionContent(sections: [sectionOne, sectionTwo, sectionThree],
tags: ["ios", "iosonly"],
staticVar: false,
extensionName: "GenTags")
// Expect Tags
extensionName: "GenAnalytics")
// Expect Analytics
let expect = """
// Generated by ResgenSwift.Tags 1.2
// Generated by ResgenSwift.Analytics 1.2
import UIKit
import MatomoTracker

View File

@ -1,5 +1,5 @@
//
// TagSectionTests.swift
// AnalyticsSectionTests.swift
//
//
// Created by Loris Perret on 06/12/2023.
@ -10,53 +10,21 @@ import XCTest
@testable import ResgenSwift
final class TagSectionTests: XCTestCase {
// MARK: - Match line
func testMatchingTagSection() {
// Given
let line = "[[section_name]]"
// When
let section = TagSection.match(line)
// Expect
XCTAssertNotNil(section)
XCTAssertEqual(section?.name, "section_name")
}
func testNotMatchingTagSection() {
// Given
let lines = ["section_name",
"[section_name]",
"[section_name",
"[[section_name",
"[[section_name]",
"section_name]",
"section_name]]",
"[section_name]]"]
// When
let matches = lines.compactMap { TagSection.match($0) }
// Expect
XCTAssertEqual(matches.isEmpty, true)
}
final class AnalyticsSectionTests: XCTestCase {
// MARK: - Matching tags
func testMatchingTags() {
func testMatchingAnalytics() {
// Given
let section = TagSection(name: "section_name")
let section = AnalyticsCategory(id: "section_name")
section.definitions = [
{
let def = TagDefinition(title: "definition_name")
let def = AnalyticsDefinition(id: "definition_name", name: "", type: .screen)
def.tags = ["ios","iosonly"]
return def
}(),
{
let def = TagDefinition(title: "definition_name_two")
let def = AnalyticsDefinition(id: "definition_name_two", name: "", type: .screen)
def.tags = ["droid","droidonly"]
return def
}()
@ -75,17 +43,17 @@ final class TagSectionTests: XCTestCase {
XCTAssertTrue(match4)
}
func testNotMatchingTags() {
func testNotMatchingAnalytics() {
// Given
let section = TagSection(name: "section_name")
let section = AnalyticsCategory(id: "section_name")
section.definitions = [
{
let def = TagDefinition(title: "definition_name")
let def = AnalyticsDefinition(id: "definition_name", name: "", type: .screen)
def.tags = ["ios","iosonly"]
return def
}(),
{
let def = TagDefinition(title: "definition_name_two")
let def = AnalyticsDefinition(id: "definition_name_two", name: "", type: .screen)
def.tags = ["droid","droidonly"]
return def
}()