Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ internal abstract class ResourcesCompatVisitorFactory : AsmClassVisitorFactory<I
private class LoadFontVisitor(api: Int, delegate: MethodVisitor) : MethodVisitor(api, delegate) {
override fun visitMethodInsn(opcode: Int, owner: String, name: String, descriptor: String, isInterface: Boolean) {
if ("startsWith" == name) {
super.visitMethodInsn(opcode, owner, "contains", "(Ljava/lang/CharSequence;)Z", isInterface)
// Skip calls to `startsWith`, return true
super.visitInsn(Opcodes.POP) // Pop the arg being passed to `startsWith`, which is "res/"
super.visitInsn(Opcodes.POP) // Pop the receiver of `startsWith`, which is the font file path
super.visitLdcInsn(1) // Push `1` to the stack, as if `startsWith` returned true
} else {
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ class PaparazziPluginTest {
assertThat(snapshotsDir.exists()).isTrue()
}

@Test
fun resourceMultiModule() {
val fixtureRoot = File("src/test/projects/resource-multi-module")

gradleRunner
.withArguments("verifyPaparazziDebug", "--stacktrace")
.forwardOutput()
.runFixture(fixtureRoot) { build() }
}

@Test
fun invalidChars() {
val fixtureRoot = File("src/test/projects/invalid-chars")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'org.jetbrains.kotlin.plugin.compose'
id 'app.cash.paparazzi'
}

android {
namespace = 'app.cash.paparazzi.plugin.test'
compileSdk = libs.versions.compileSdk.get() as int
defaultConfig {
minSdk = libs.versions.minSdk.get() as int
}
compileOptions {
sourceCompatibility = libs.versions.javaTarget.get()
targetCompatibility = libs.versions.javaTarget.get()
}
kotlinOptions {
jvmTarget = libs.versions.javaTarget.get()
}
buildFeatures {
compose = true
}
}

dependencies {
implementation project(':typography')

implementation libs.composeUi.material
implementation libs.androidx.appcompat
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!--
~ Copyright (C) 2018 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<manifest package="app.cash.paparazzi.plugin.test">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package app.cash.paparazzi.plugin.test

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import app.cash.paparazzi.plugin.typography.GreatVibes

@Composable
fun CustomFont() {
MaterialTheme {
Box(Modifier.fillMaxSize().background(color = Color.White)) {
Text(
text = "Hello, Paparazzi!",
style = TextStyle(
fontFamily = GreatVibes
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2020 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package app.cash.paparazzi.plugin.test

import android.widget.LinearLayout
import app.cash.paparazzi.Paparazzi
import org.junit.Rule
import org.junit.Test

class VerifyTest {
@get:Rule
val paparazzi = Paparazzi()

@Test
fun verify() {
paparazzi.snapshot {
CustomFont()
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apply from: '../test.settings.gradle'

include ':app'
include ':typography'
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'org.jetbrains.kotlin.plugin.compose'
}

android {
namespace = 'app.cash.paparazzi.plugin.typography'
compileSdk = libs.versions.compileSdk.get() as int
defaultConfig {
minSdk = libs.versions.minSdk.get() as int
}
compileOptions {
sourceCompatibility = libs.versions.javaTarget.get()
targetCompatibility = libs.versions.javaTarget.get()
}
kotlinOptions {
jvmTarget = libs.versions.javaTarget.get()
}
buildFeatures {
compose = true
}
}

dependencies {
implementation libs.composeUi.material
implementation libs.androidx.appcompat
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2020 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package app.cash.paparazzi.plugin.typography

import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import app.cash.paparazzi.plugin.typography.R

val GreatVibes = FontFamily(
Font(
resId = R.font.cashmarket_medium_normal,
weight = FontWeight.Normal,
FontStyle.Normal
)
)
Binary file not shown.
Loading